summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorkonsumlamm <44230978+konsumlamm@users.noreply.github.com>2022-09-28 13:59:27 +0200
committerGitHub <noreply@github.com>2022-09-28 13:59:27 +0200
commit18cea8e9bd9b747e085974d1afc99fd71fe19fa6 (patch)
tree6c6582252e0ed597c69a6e0436b9f2de720a5e5e /compiler
parente33e9e4a32ea19654d1940ad0c17da8490a99f6c (diff)
downloadNim-18cea8e9bd9b747e085974d1afc99fd71fe19fa6.tar.gz
Update message for checking `cast` (#20145)
* Update message for checking `cast`

* Update error messages in tests
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semexprs.nim10
1 files changed, 5 insertions, 5 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 90e2f2b23..32bb4c331 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -241,7 +241,10 @@ proc isCastable(c: PContext; dst, src: PType, info: TLineInfo): bool =
         (skipTypes(dst, abstractInst).kind in IntegralTypes) or
         (skipTypes(src, abstractInst-{tyTypeDesc}).kind in IntegralTypes)
     if result and (dstSize > srcSize):
-      message(conf, info, warnCastSizes, "target type is larger than source type")
+      var warnMsg = "target type is larger than source type"
+      warnMsg.add("\n  target type: '$1' ($2)" % [$dst, if dstSize == 1: "1 byte" else: $dstSize & " bytes"])
+      warnMsg.add("\n  source type: '$1' ($2)" % [$src, if srcSize == 1: "1 byte" else: $srcSize & " bytes"])
+      message(conf, info, warnCastSizes, warnMsg)
   if result and src.kind == tyNil:
     return dst.size <= conf.target.ptrSize
 
@@ -363,10 +366,7 @@ proc semCast(c: PContext, n: PNode): PNode =
   if tfHasMeta in targetType.flags:
     localError(c.config, n[0].info, "cannot cast to a non concrete type: '$1'" % $targetType)
   if not isCastable(c, targetType, castedExpr.typ, n.info):
-    let tar = $targetType
-    let alt = typeToString(targetType, preferDesc)
-    let msg = if tar != alt: tar & "=" & alt else: tar
-    localError(c.config, n.info, "expression cannot be cast to " & msg)
+    localError(c.config, n.info, "expression cannot be cast to '$1'" % $targetType)
   result = newNodeI(nkCast, n.info)
   result.typ = targetType
   result.add copyTree(n[0])