diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-04-30 01:12:36 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2016-04-30 01:12:36 +0200 |
commit | f348671ba7146420e1bfc7cd21ddc5464f0b9cb3 (patch) | |
tree | 490b6c4c73bd5681bd3411dea9a84c43a9e1dd01 /compiler/semexprs.nim | |
parent | e04f3195407cc99f958dd81e0a9d58fe5414e631 (diff) | |
download | Nim-f348671ba7146420e1bfc7cd21ddc5464f0b9cb3.tar.gz |
fixes #3544
Diffstat (limited to 'compiler/semexprs.nim')
-rw-r--r-- | compiler/semexprs.nim | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 3c4c453a9..105667aab 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -87,8 +87,9 @@ type convNotNeedeed, convNotLegal -proc checkConversionBetweenObjects(castDest, src: PType): TConvStatus = - return if inheritanceDiff(castDest, src) == high(int): +proc checkConversionBetweenObjects(castDest, src: PType; pointers: int): TConvStatus = + let diff = inheritanceDiff(castDest, src) + return if diff == high(int) or (pointers > 1 and diff != 0): convNotLegal else: convOK @@ -105,13 +106,15 @@ proc checkConvertible(c: PContext, castDest, src: PType): TConvStatus = return var d = skipTypes(castDest, abstractVar) var s = skipTypes(src, abstractVar-{tyTypeDesc}) + var pointers = 0 while (d != nil) and (d.kind in {tyPtr, tyRef}) and (d.kind == s.kind): d = d.lastSon s = s.lastSon + inc pointers if d == nil: result = convNotLegal elif d.kind == tyObject and s.kind == tyObject: - result = checkConversionBetweenObjects(d, s) + result = checkConversionBetweenObjects(d, s, pointers) elif (skipTypes(castDest, abstractVarRange).kind in IntegralTypes) and (skipTypes(src, abstractVarRange-{tyTypeDesc}).kind in IntegralTypes): # accept conversion between integral types |