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

ignore uninstantiated static on match to base type [backport:2.0] #23731

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Jun 18, 2024

fixes #23730

Since #23188 the compiler errors when matching a type variable to an uninstantiated static value. However sometimes an uninstantiated static value is given even when only a type match is being performed to the base type of the static type, in the given issue this case is:

proc foo[T: SomeInteger](x: T): int = int(x)
proc bar(x: static int): array[foo(x), int] = discard
discard bar(123)

To deal with this issue we only error when matching against a type variable constrained to static.

Not sure if the q.typ.kind == tyGenericParam and q.typ.genericConstraint == tyStatic check is necessary, the code above for deciding whether the variable becomes skConst doesn't use it.

@metagn metagn changed the title ignore uninstantiated static on match to base type ignore uninstantiated static on match to base type [backport:2.0] Jun 18, 2024
@Araq Araq merged commit 128090c into nim-lang:devel Jun 18, 2024
18 of 19 checks passed
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 128090c

Hint: mm: orc; opt: speed; options: -d:release
178820 lines; 8.491s; 664.246MiB peakmem

narimiran pushed a commit that referenced this pull request Jun 24, 2024
…3731)

fixes #23730

Since #23188 the compiler errors when matching a type variable to an
uninstantiated static value. However sometimes an uninstantiated static
value is given even when only a type match is being performed to the
base type of the static type, in the given issue this case is:

```nim
proc foo[T: SomeInteger](x: T): int = int(x)
proc bar(x: static int): array[foo(x), int] = discard
discard bar(123)
```

To deal with this issue we only error when matching against a type
variable constrained to `static`.

Not sure if the `q.typ.kind == tyGenericParam and
q.typ.genericConstraint == tyStatic` check is necessary, the code above
for deciding whether the variable becomes `skConst` doesn't use it.

(cherry picked from commit 128090c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

regression from 2.0.4 to 2.0.6 cannot instantiate: 'SomeInteger' in return type
2 participants