mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-05 03:14:08 +00:00
* fixes #22054; codegen for var tuples conv
* rethink fixes
* add test cases
* templates only
* fixes var tuples
* keep varness no matter what
* fixes typ.isNil
* make it work for generics
* restore isSubrange
* add a test case as requested
(cherry picked from commit 77beb15214)
This commit is contained in:
@@ -1888,7 +1888,13 @@ proc implicitConv(kind: TNodeKind, f: PType, arg: PNode, m: TCandidate,
|
||||
else:
|
||||
result.typ = errorType(c)
|
||||
else:
|
||||
result.typ = f.skipTypes({tySink, tyVar})
|
||||
result.typ = f.skipTypes({tySink})
|
||||
# keep varness
|
||||
if arg.typ != nil and arg.typ.kind == tyVar:
|
||||
result.typ = toVar(result.typ, tyVar, c.idgen)
|
||||
else:
|
||||
result.typ = result.typ.skipTypes({tyVar})
|
||||
|
||||
if result.typ == nil: internalError(c.graph.config, arg.info, "implicitConv")
|
||||
result.add c.graph.emptyNode
|
||||
result.add arg
|
||||
|
||||
9
tests/errmsgs/t22097.nim
Normal file
9
tests/errmsgs/t22097.nim
Normal file
@@ -0,0 +1,9 @@
|
||||
discard """
|
||||
errormsg: "for a 'var' type a variable needs to be passed; but 'uint16(x)' is immutable"
|
||||
"""
|
||||
|
||||
proc toUInt16(x: var uint16) =
|
||||
discard
|
||||
|
||||
var x = uint8(1)
|
||||
toUInt16 x
|
||||
@@ -171,3 +171,29 @@ block tuple_with_seq:
|
||||
echo s
|
||||
(s, 7)
|
||||
t = test(t.a)
|
||||
|
||||
block: # bug #22049
|
||||
type A = object
|
||||
field: tuple[a, b, c: seq[int]]
|
||||
|
||||
func value(v: var A): var tuple[a, b, c: seq[int]] =
|
||||
v.field
|
||||
template get(v: A): tuple[a, b, c: seq[int]] = v.value
|
||||
|
||||
var v = A(field: (@[1], @[2], @[3]))
|
||||
var (a, b, c) = v.get()
|
||||
|
||||
doAssert a == @[1]
|
||||
doAssert b == @[2]
|
||||
doAssert c == @[3]
|
||||
|
||||
block: # bug #22054
|
||||
type A = object
|
||||
field: tuple[a: int]
|
||||
|
||||
func value(v: var A): var tuple[a: int] =
|
||||
v.field
|
||||
template get(v: A): tuple[a: int] = v.value
|
||||
|
||||
var v = A(field: (a: 1314))
|
||||
doAssert get(v)[0] == 1314
|
||||
|
||||
Reference in New Issue
Block a user