Skip to content

Commit

Permalink
add workaround & explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Oct 4, 2024
1 parent 02db517 commit 7104371
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,13 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
result = arg
elif skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple or cmpInheritancePenalty(oldInheritancePenalty, m.inheritancePenalty) > 0:
result = implicitConv(nkHiddenSubConv, f, arg, m, c)
elif arg.typ.isEmptyContainer or arg.typ.isIntLit:
elif arg.typ.isEmptyContainer or
# XXX `and not m.isNoCall` is a workaround
# passing an int to generic types converts it to the type `int`
# but this isn't done for int literal types, so we preserve the type
# i.e. works: `type Foo[T] = array[T, int]; var x: Foo[3]` (see t12938, t14193)
# doesn't work: `proc foo[T](): array[T, int] = ...; foo[3]()` (see #23204)
(arg.typ.isIntLit and not m.isNoCall):
result = arg.copyTree
result.typ = getInstantiatedType(c, arg, m, f).skipTypes({tySink})
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/generics/t14193.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type
Task*[N: int] = object
Task*[N: int] = object # XXX this shouldn't work, should be `static int`
env*: array[N, byte]

var task14193: Task[20]
Expand Down

0 comments on commit 7104371

Please sign in to comment.