alternative to #18918 (#18927)

* fix #16558

* add testcase
This commit is contained in:
flywind 2021-09-30 22:57:06 +08:00 • committed by GitHub
commit 677969f6ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View file

@ -217,6 +217,8 @@ proc isCastable(c: PContext; dst, src: PType): bool =
let s = skipTypes(src, abstractInst) let s = skipTypes(src, abstractInst)
if d.kind == tyRef and s.kind == tyRef and s[0].isFinal != d[0].isFinal: if d.kind == tyRef and s.kind == tyRef and s[0].isFinal != d[0].isFinal:
return false return false
elif d.kind in IntegralTypes and s.kind in {tyString, tySequence}:
return false
var dstSize, srcSize: BiggestInt var dstSize, srcSize: BiggestInt
dstSize = computeSize(conf, dst) dstSize = computeSize(conf, dst)

9
tests/arc/t16558.nim Normal file
View file

@ -0,0 +1,9 @@
discard """
matrix: "--gc:arc"
errormsg: "expression cannot be cast to int"
"""
block: # bug #16558
var value = "hi there"
var keepInt: int
keepInt = cast[int](value)