summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-05-31 22:53:36 +0200
committerAndreas Rumpf <rumpf_a@web.de>2014-05-31 22:53:36 +0200
commitcbe25a41b031ea8c36dce1b47c26fd7682e40a82 (patch)
treeaeb217558dd6a589393b923531507cd87768cd1f
parent6ae46265cc327b94f8841a0acf7ce967af8eeb75 (diff)
parent9d68fe378203f4cdd9edc412b8d0b0f6b422fb14 (diff)
downloadNim-cbe25a41b031ea8c36dce1b47c26fd7682e40a82.tar.gz
Merge pull request #1229 from Varriount/fix-1203
Fix issue #1203
-rw-r--r--compiler/semexprs.nim22
1 files changed, 14 insertions, 8 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 1c7115cd0..99ffa9b54 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -176,21 +176,26 @@ proc checkConvertible(c: PContext, castDest, src: PType): TConvStatus =
     else:
       discard
 
-proc isCastable(dst, src: PType): bool = 
+proc isCastable(dst, src: PType): bool =
+  ## Checks whether the source type can be casted to the destination type.
+  ## Casting is very unrestrictive; casts are allowed as long as 
+  ## castDest.size >= src.size, and typeAllowed(dst, skParam)
   #const
   #  castableTypeKinds = {tyInt, tyPtr, tyRef, tyCstring, tyString, 
   #                       tySequence, tyPointer, tyNil, tyOpenArray,
   #                       tyProc, tySet, tyEnum, tyBool, tyChar}
-  var ds, ss: BiggestInt
-  # this is very unrestrictive; cast is allowed if castDest.size >= src.size
-  ds = computeSize(dst)
-  ss = computeSize(src)
-  if ds < 0: 
+  var dstSize, srcSize: BiggestInt
+
+  dstSize = computeSize(dst)
+  srcSize = computeSize(src)
+  if dstSize < 0: 
+    result = false
+  elif srcSize < 0: 
     result = false
-  elif ss < 0: 
+  elif not typeAllowed(dst, skParam):
     result = false
   else: 
-    result = (ds >= ss) or
+    result = (dstSize >= srcSize) or
         (skipTypes(dst, abstractInst).kind in IntegralTypes) or
         (skipTypes(src, abstractInst-{tyTypeDesc}).kind in IntegralTypes)
   
@@ -254,6 +259,7 @@ proc semConv(c: PContext, n: PNode): PNode =
     localError(n.info, errUseQualifier, op.sons[0].sym.name.s)
 
 proc semCast(c: PContext, n: PNode): PNode = 
+  ## Semantically analyze a casting ("cast[type](param)")
   if optSafeCode in gGlobalOptions: localError(n.info, errCastNotInSafeMode)
   #incl(c.p.owner.flags, sfSideEffect)
   checkSonsLen(n, 2)