Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix calls to implicitly generic params in generic contexts #24246

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,9 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode =
if liftLhs:
n[1] = makeTypeSymNode(c, lhsType, n[1].info)
lhsType = n[1].typ
else:
if c.inGenericContext > 0 and lhsType.base.containsUnresolvedType:
# BUGFIX: don't evaluate this too early: ``T is void``
return
if c.inGenericContext > 0 and lhsType.containsUnresolvedType:
# BUGFIX: don't evaluate this too early: ``T is void``
return

result = isOpImpl(c, n, flags)

Expand Down
3 changes: 2 additions & 1 deletion compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,8 @@ proc containsGenericType*(t: PType): bool =
result = iterOverType(t, containsGenericTypeIter, nil)

proc containsUnresolvedTypeIter(t: PType, closure: RootRef): bool =
if tfUnresolved in t.flags: return true
if {tfUnresolved, tfGenericTypeParam, tfImplicitTypeParam} * t.flags != {}:
return true
case t.kind
of tyStatic:
return t.n == nil
Expand Down
36 changes: 36 additions & 0 deletions tests/proc/tgenericdefaultparam.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,39 @@ block: # issue #24121
proc baz[T: FooBar](x: T, y = foo(x)): string = y
doAssert baz(Foo(123)) == "b"
doAssert baz(Bar(123)) == "c"

block: # using `or` type
template val(x: int): string = "int"
template val(x: string): string = "string"
proc foo(x: int | string, y = val(x)): string =
y

doAssert foo(123) == "int"
doAssert foo("abc") == "string"

block: # using concept type
type Foo = concept x
x is int | string
template val(x: int): string = "int"
template val(x: string): string = "string"
proc foo(x: Foo, y = val(x)): string =
y

doAssert foo(123) == "int"
doAssert foo("abc") == "string"

block: # using `or` type with direct `is`
proc foo(x: int | string, y = when x is int: "int" else: "string"): string =
y

doAssert foo(123) == "int"
doAssert foo("abc") == "string"

block: # using concept type with direct `is`
type Foo = concept x
x is int | string
proc foo(x: Foo, y = when x is int: "int" else: "string"): string =
y

doAssert foo(123) == "int"
doAssert foo("abc") == "string"