mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-11 22:08:54 +00:00
* cheap fix for #10853 * also better tuple subscript error message * weird
This commit is contained in:
@@ -132,7 +132,7 @@ proc lowerTupleUnpackingForAsgn*(g: ModuleGraph; n: PNode; idgen: IdGenerator; o
|
||||
|
||||
var vpart = newNodeI(nkIdentDefs, tempAsNode.info, 3)
|
||||
vpart[0] = tempAsNode
|
||||
vpart[1] = newNodeI(nkEmpty, value.info)
|
||||
vpart[1] = newNodeI(nkTupleClassTy, value.info)
|
||||
vpart[2] = value
|
||||
v.add vpart
|
||||
result.add(v)
|
||||
|
||||
@@ -1646,7 +1646,10 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||
{tyInt..tyInt64}:
|
||||
let idx = getOrdValue(n[1])
|
||||
if idx >= 0 and idx < arr.len: n.typ = arr[toInt(idx)]
|
||||
else: localError(c.config, n.info, "invalid index value for tuple subscript")
|
||||
else:
|
||||
localError(c.config, n.info,
|
||||
"invalid index $1 in subscript for tuple of length $2" %
|
||||
[$idx, $arr.len])
|
||||
result = n
|
||||
else:
|
||||
result = nil
|
||||
|
||||
3
tests/errmsgs/tassignunpack.nim
Normal file
3
tests/errmsgs/tassignunpack.nim
Normal file
@@ -0,0 +1,3 @@
|
||||
var a, b = 0
|
||||
(a, b) = 1 #[tt.Error
|
||||
^ type mismatch: got <int literal(1)> but expected 'tuple']#
|
||||
2
tests/errmsgs/ttupleindexoutofbounds.nim
Normal file
2
tests/errmsgs/ttupleindexoutofbounds.nim
Normal file
@@ -0,0 +1,2 @@
|
||||
let a = (1, 2)[4] #[tt.Error
|
||||
^ invalid index 4 in subscript for tuple of length 2]#
|
||||
@@ -1,5 +1,5 @@
|
||||
discard """
|
||||
errormsg: "cannot infer the type of the tuple"
|
||||
errormsg: "invalid type: 'empty' in this context: '(seq[empty], (seq[empty], set[empty]))' for let"
|
||||
file: "tassignemptytuple.nim"
|
||||
line: 11
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user