fixes #25494; [regression] Crash on enum ranges as default parameters in generic procs (#25496)

fixes #25494;

(cherry picked from commit ae5f864bff)
This commit is contained in:
ringabout
2026-02-09 18:50:45 +08:00
committed by narimiran
parent becb06dd70
commit 29125f0bc7
2 changed files with 14 additions and 4 deletions

View File

@@ -813,7 +813,7 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PTyp
inc(lastIndex)
if isGeneric:
for i in 0..<result.len:
if isIntLit(result[i].typ):
if result[i].typ != nil and isIntLit(result[i].typ):
# generic instantiation strips int lit type which makes conversions fail
result[i].typ() = nil
result.typ() = nil # current result.typ is invalid, index type is nil
@@ -2799,7 +2799,7 @@ proc semSetConstr(c: PContext, n: PNode, expectedType: PType = nil): PNode =
expectedElementType = typ
if isGeneric:
for i in 0..<n.len:
if isIntLit(n[i].typ):
if n[i].typ != nil and isIntLit(n[i].typ):
# generic instantiation strips int lit type which makes conversions fail
n[i].typ() = nil
result.add n[i]
@@ -2912,7 +2912,7 @@ proc semTupleFieldsConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType
result.add n[i]
if isGeneric:
for i in 0..<result.len:
if isIntLit(result[i][1].typ):
if result[i][1].typ != nil and isIntLit(result[i][1].typ):
# generic instantiation strips int lit type which makes conversions fail
result[i][1].typ() = nil
result.typ() = makeTypeFromExpr(c, result.copyTree)
@@ -2953,7 +2953,7 @@ proc semTuplePositionsConstr(c: PContext, n: PNode, flags: TExprFlags; expectedT
addSonSkipIntLit(typ, n[i].typ.skipTypes({tySink}), c.idgen)
if isGeneric:
for i in 0..<result.len:
if isIntLit(result[i].typ):
if result[i].typ != nil and isIntLit(result[i].typ):
# generic instantiation strips int lit type which makes conversions fail
result[i].typ() = nil
result.typ() = makeTypeFromExpr(c, result.copyTree)

View File

@@ -892,3 +892,13 @@ block: # https://github.com/nim-lang/Nim/issues/20416
proc p2[T](sg:Container[T]) = discard
var v : Container[int]
p2(v)
block: # issue #25494
proc foo[T: enum](s = {T.low..T.high}) =
discard
type
MyEnum = enum
a, b, c
foo[MyEnum]()