Fixed const tuples in inferred generics (#18598)

This commit is contained in:
Jason Beetham
2021-07-27 01:36:59 -06:00
committed by GitHub
parent fa0209609d
commit ed44618deb
2 changed files with 30 additions and 17 deletions

View File

@@ -391,16 +391,24 @@ proc semGenericStmt(c: PContext, n: PNode,
a[^1] = semGenericStmtScope(c, a[^1], flags, ctx)
closeScope(c)
of nkVarSection, nkLetSection:
of nkVarSection, nkLetSection, nkConstSection:
let varKind =
case n.kind
of nkVarSection: skVar
of nkLetSection: skLet
else: skConst
for i in 0..<n.len:
var a = n[i]
if a.kind == nkCommentStmt: continue
if (a.kind != nkIdentDefs) and (a.kind != nkVarTuple): illFormedAst(a, c.config)
checkMinSonsLen(a, 3, c.config)
a[^2] = semGenericStmt(c, a[^2], flags+{withinTypeDesc}, ctx)
a[^1] = semGenericStmt(c, a[^1], flags, ctx)
for j in 0..<a.len-2:
addTempDecl(c, getIdentNode(c, a[j]), skVar)
case a.kind:
of nkCommentStmt: continue
of nkIdentDefs, nkVarTuple, nkConstDef:
checkMinSonsLen(a, 3, c.config)
a[^2] = semGenericStmt(c, a[^2], flags+{withinTypeDesc}, ctx)
a[^1] = semGenericStmt(c, a[^1], flags, ctx)
for j in 0..<a.len-2:
addTempDecl(c, getIdentNode(c, a[j]), varKind)
else:
illFormedAst(a, c.config)
of nkGenericParams:
for i in 0..<n.len:
var a = n[i]
@@ -410,15 +418,6 @@ proc semGenericStmt(c: PContext, n: PNode,
# do not perform symbol lookup for default expressions
for j in 0..<a.len-2:
addTempDecl(c, getIdentNode(c, a[j]), skType)
of nkConstSection:
for i in 0..<n.len:
var a = n[i]
if a.kind == nkCommentStmt: continue
if (a.kind != nkConstDef): illFormedAst(a, c.config)
checkSonsLen(a, 3, c.config)
addTempDecl(c, getIdentNode(c, a[0]), skConst)
a[1] = semGenericStmt(c, a[1], flags+{withinTypeDesc}, ctx)
a[2] = semGenericStmt(c, a[2], flags, ctx)
of nkTypeSection:
for i in 0..<n.len:
var a = n[i]

View File

@@ -0,0 +1,14 @@
discard """
action: run
"""
block:
proc something(a: string or int or float) =
const (c, d) = (default a.type, default a.type)
block:
proc something(a: string or int) =
const c = default a.type
block:
proc something(a: string or int) =
const (c, d, e) = (default a.type, default a.type, default a.type)