summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-09-17 22:45:12 +0200
committerGitHub <noreply@github.com>2018-09-17 22:45:12 +0200
commit9c6dde1b707b1ccc58c183047ee149a6c70b7e10 (patch)
tree3f447010be630399c9ff9a1a97ab78deb2c2d9fe
parent97fefa3f50a7a594d57b25dcda4ef36f88df8364 (diff)
parent3588240226187152f618febb8c01a034084ce772 (diff)
downloadNim-9c6dde1b707b1ccc58c183047ee149a6c70b7e10.tar.gz
Merge pull request #8990 from LemonBoy/fix-8259
Always check the deduced type validity for result
-rw-r--r--compiler/semexprs.nim2
-rw-r--r--tests/openarray/t8259.nim7
2 files changed, 9 insertions, 0 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 61c530f61..e683984c5 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -1560,6 +1560,8 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
           rhsTyp = rhsTyp.lastSon
         if cmpTypes(c, lhs.typ, rhsTyp) in {isGeneric, isEqual}:
           internalAssert c.config, c.p.resultSym != nil
+          # Make sure the type is valid for the result variable
+          typeAllowedCheck(c.config, n.info, rhsTyp, skResult)
           lhs.typ = rhsTyp
           c.p.resultSym.typ = rhsTyp
           c.p.owner.typ.sons[0] = rhsTyp
diff --git a/tests/openarray/t8259.nim b/tests/openarray/t8259.nim
new file mode 100644
index 000000000..40ff2b2f1
--- /dev/null
+++ b/tests/openarray/t8259.nim
@@ -0,0 +1,7 @@
+discard """
+  line: 6
+  errormsg: "invalid type: 'openarray[int]' for result"
+"""
+
+proc foo(a: openArray[int]):auto = a
+echo foo(toOpenArray([1, 2], 0, 2))