mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 21:40:32 +00:00
(cherry picked from commit 77e58bf573)
This commit is contained in:
@@ -2430,12 +2430,16 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags; expectedType: P
|
||||
markUsed(c, n.info, s)
|
||||
result = semSizeof(c, setMs(n, s))
|
||||
of mArrToSeq, mOpenArrayToSeq:
|
||||
if n.len == 2 and expectedType != nil and (
|
||||
if expectedType != nil and (
|
||||
let expected = expectedType.skipTypes(abstractRange-{tyDistinct});
|
||||
expected.kind in {tySequence, tyOpenArray}):
|
||||
# seq type inference
|
||||
var arrayType = newType(tyOpenArray, nextTypeId(c.idgen), expected.owner)
|
||||
arrayType.rawAddSon(expected[0])
|
||||
if n[0].kind == nkSym and sfFromGeneric in n[0].sym.flags:
|
||||
# may have been resolved to `@`[empty] at some point,
|
||||
# reset to `@` to deal with this
|
||||
n[0] = newSymNode(n[0].sym.owner, n[0].info)
|
||||
n[1] = semExpr(c, n[1], flags, arrayType)
|
||||
result = semDirectOp(c, n, flags, expectedType)
|
||||
else:
|
||||
|
||||
@@ -244,3 +244,14 @@ block: # bug #11777
|
||||
type S = set[0..5]
|
||||
var s: S = {1, 2}
|
||||
doAssert 1 in s
|
||||
|
||||
block: # regression #20807
|
||||
var s: seq[string]
|
||||
template fail =
|
||||
s = @[]
|
||||
template test(body: untyped) =
|
||||
body
|
||||
proc test(a: string) = discard
|
||||
test: fail()
|
||||
doAssert not (compiles do:
|
||||
let x: seq[int] = `@`[string]([]))
|
||||
|
||||
Reference in New Issue
Block a user