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

regression from 2.0.4 to 2.0.6 cannot instantiate: 'SomeInteger' in return type #23730

Closed
daniel-j opened this issue Jun 17, 2024 · 1 comment · Fixed by #23731
Closed

regression from 2.0.4 to 2.0.6 cannot instantiate: 'SomeInteger' in return type #23730

daniel-j opened this issue Jun 17, 2024 · 1 comment · Fixed by #23731

Comments

@daniel-j
Copy link
Contributor

Description

When using a static parameter as right hand side argument to a function like shl (which takes a SomeInteger as 2nd argument) the Nim compiler throws an error. This is a regression I noticed when upgrading to Nim 2.0.6.

Test code:

proc test(M: static[int]): array[1 shl M, int] = discard
echo len(test(3))

Nim Version

Nim Compiler Version 2.0.6 [Linux: amd64]
Compiled at 2024-06-17
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: c00e8e7
active boot switches: -d:release

Current Output

/usercode/in.nim(1, 36) template/generic instantiation of `shl` from here
/playground/nim/lib/system/arithmetics.nim(158, 21) Error: cannot instantiate: 'SomeInteger'

Expected Output

8

Possible Solution

No response

Additional Information

No response

@metagn
Copy link
Collaborator

metagn commented Jun 18, 2024

Culprit is #23188, we check for generic parameters that are instantiated with unresolved statics, but in this case the parameter getting instantiated is only matching that it is int, not the actual static value. I am hoping that checking that the matched type is tyStatic is enough to deal with this.

metagn added a commit to metagn/Nim that referenced this issue Jun 18, 2024
Araq pushed a commit that referenced this issue Jun 18, 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.
narimiran pushed a commit that referenced this issue 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 a pull request may close this issue.

2 participants