summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-09-09 14:20:10 +0200
committerGitHub <noreply@github.com>2020-09-09 14:20:10 +0200
commit3f00a738dbc8319b4dd2b86bf5529c096f2dd243 (patch)
tree1e730a512147d2d9de9fba8772921327c5d8ac62
parent217675cf84dc47bb68f03b341aff14315804efec (diff)
downloadNim-3f00a738dbc8319b4dd2b86bf5529c096f2dd243.tar.gz
fixes #15280 [backport:1.2] (#15281)
* fixes #15280 [backport:1.2]

* make tests green again

* adapt tests
-rw-r--r--compiler/sem.nim2
-rw-r--r--tests/arc/tmovebug.nim6
-rw-r--r--tests/casestmt/tcasestmt.nim2
-rw-r--r--tests/semreject/tmixing_return_and_exprs.nim44
4 files changed, 49 insertions, 5 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 705e1b72c..bc6119460 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -184,7 +184,7 @@ proc endsInNoReturn(n: PNode): bool =
   var it = n
   while it.kind in {nkStmtList, nkStmtListExpr} and it.len > 0:
     it = it.lastSon
-  result = it.kind in nkLastBlockStmts or
+  result = it.kind in (nkLastBlockStmts-{nkReturnStmt}) or
     it.kind in nkCallKinds and it[0].kind == nkSym and sfNoReturn in it[0].sym.flags
 
 proc commonType*(x: PType, y: PNode): PType =
diff --git a/tests/arc/tmovebug.nim b/tests/arc/tmovebug.nim
index 3b7a7c5df..c735ea1eb 100644
--- a/tests/arc/tmovebug.nim
+++ b/tests/arc/tmovebug.nim
@@ -502,7 +502,7 @@ weirdScopes()
 # bug #14985
 proc getScope(): string =
   if true:
-    return "hi"
+    "hi"
   else:
     "else"
 
@@ -512,14 +512,14 @@ proc getScope3(): string =
   try:
     "try"
   except:
-    return "except"
+    "except"
 
 echo getScope3()
 
 proc getScope2(): string =
   case true
   of true:
-    return "bye"
+    "bye"
   else:
     "else"
 
diff --git a/tests/casestmt/tcasestmt.nim b/tests/casestmt/tcasestmt.nim
index 53cccdb64..2151892aa 100644
--- a/tests/casestmt/tcasestmt.nim
+++ b/tests/casestmt/tcasestmt.nim
@@ -258,7 +258,7 @@ func foo(input: string): int =
   try:
     parseInt(input)
   except:
-    return
+    0
 
 func foo2(b, input: string): int =
   case b:
diff --git a/tests/semreject/tmixing_return_and_exprs.nim b/tests/semreject/tmixing_return_and_exprs.nim
new file mode 100644
index 000000000..2848c47e4
--- /dev/null
+++ b/tests/semreject/tmixing_return_and_exprs.nim
@@ -0,0 +1,44 @@
+discard """
+  errormsg: "expression 'len(src) shl 1' is of type 'int' and has to be used (or discarded)"
+  line: 19
+"""
+
+# bug #15280
+
+type
+  HexFlags* {.pure.} = enum
+    LowerCase,  ## Produce lowercase hexadecimal characters
+    PadOdd,     ## Pads odd strings
+    SkipSpaces, ## Skips all the whitespace characters inside of string
+    SkipPrefix  ## Skips `0x` and `x` prefixes at the begining of string
+
+
+proc bytesToHex*(src: openarray[byte], dst: var openarray[char],
+                 flags: set[HexFlags]): int =
+  if len(dst) == 0:
+    (len(src) shl 1)
+  else:
+    var halflast = false
+    let dstlen = len(dst)
+    var srclen = len(src)
+
+    if dstlen < (srclen shl 1):
+      if (dstlen and 1) == 1:
+        srclen = (dstlen - 1) shr 1
+        halflast = true
+      else:
+        srclen = (dstlen shr 1)
+
+    let lowercase = (HexFlags.LowerCase in flags)
+
+    var k = 0
+    for i in 0 ..< srclen:
+      let x = int(src[i])
+      inc(k, 2)
+
+    if halflast:
+      let x = int(src[srclen])
+      inc(k)
+
+    return k
+
g/Nim/blame/.gitignore?h=devel&id=c66580911eeffa96601f12fdbe640bffb3f3b121'>^
0879f0b0a ^
a1203cf84 ^
d20a8ac68 ^
b2e486b23 ^
9af85fb69 ^
1b1bb284d ^
1dd9ec85b ^
f2f16f645 ^






ca4b971bc ^
f2f16f645 ^


f04b502cf ^

9b29436f6 ^
f04b502cf ^

5a4122dc9 ^
809a4a77a ^

e9b665f33 ^

c60bb9464 ^
e9b665f33 ^

f04b502cf ^
1b1bb284d ^
809a4a77a ^

dce0b3b00 ^
b77ae66e8 ^
dce0b3b00 ^

93cd98dd1 ^
b7dd8e7df ^
5263d9d6f ^



035f0fb02 ^
25b4a0ab0 ^
035f0fb02 ^

8d2953e80 ^
e9b665f33 ^
a5ecbf823 ^

25b4a0ab0 ^


606288974 ^
25b4a0ab0 ^
4a720394b ^


16e800503 ^

4a720394b ^
88b5dd336 ^
c5c6bae2a ^

e5ae7ceaa ^
6e4cd3e5b ^

e5ae7ceaa ^

1b54be777 ^
567691220 ^

58282547f ^


44f672a51 ^

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111