summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflywind <xzsflywind@gmail.com>2021-09-30 22:57:06 +0800
committerGitHub <noreply@github.com>2021-09-30 16:57:06 +0200
commit677969f6eaac108fc5fda776095a710c1b3b197a (patch)
treed3e8afb4b4d7d6f25d04e759816bd5d9df5620ba
parentf915b3aa86929d87e162b6ddd7589e6337a30397 (diff)
downloadNim-677969f6eaac108fc5fda776095a710c1b3b197a.tar.gz
alternative to #18918 (#18927)
* fix #16558

* add testcase
-rw-r--r--compiler/semexprs.nim2
-rw-r--r--tests/arc/t16558.nim9
2 files changed, 11 insertions, 0 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 9134c1301..342b8b05f 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -217,6 +217,8 @@ proc isCastable(c: PContext; dst, src: PType): bool =
     let s = skipTypes(src, abstractInst)
     if d.kind == tyRef and s.kind == tyRef and s[0].isFinal != d[0].isFinal:
       return false
+    elif d.kind in IntegralTypes and s.kind in {tyString, tySequence}:
+      return false
 
   var dstSize, srcSize: BiggestInt
   dstSize = computeSize(conf, dst)
diff --git a/tests/arc/t16558.nim b/tests/arc/t16558.nim
new file mode 100644
index 000000000..7b6eb4669
--- /dev/null
+++ b/tests/arc/t16558.nim
@@ -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)
52383235bc0f0435260ea2296182effdfd1b'>05fe52383 ^
96c571dd9 ^
05fe52383 ^



9f6f78ac6 ^






c525dfabc ^

9f6f78ac6 ^






931496770 ^
9f6f78ac6 ^

931496770 ^
9f6f78ac6 ^
ffd929af4 ^
9f6f78ac6 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62