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

"type expected" error for proc resolution with static[int]] #10833

Open
Nycto opened this issue Mar 12, 2019 · 1 comment
Open

"type expected" error for proc resolution with static[int]] #10833

Nycto opened this issue Mar 12, 2019 · 1 comment

Comments

@Nycto
Copy link
Contributor

Nycto commented Mar 12, 2019

I expect the example below to compile, but it instead fails with a cryptic error message

Example

type Foo*[A; B; C: static[int]] = object

proc build*[A; B; C: static[int]](field: string): Foo[A, B, C] =
    discard

proc build*[A; B; C: static[int]](): Foo[A, B, C] =
    build[A, B, C]("foo")

type
    Bar = object
    Baz = object

discard build[Bar, Baz, 1]()

Current Output

foo.nim(13, 14) template/generic instantiation from here
foo.nim(7, 17) Error: type expected

Expected Output

I expect this code to compile

Possible Solution

I have no proposed solution, but I've found that renaming one of the methods works around the bug:

type Foo*[A; B; C: static[int]] = object

proc build*[A; B; C: static[int]](field: string): Foo[A, B, C] =
    discard

proc buildThing*[A; B; C: static[int]](): Foo[A, B, C] =
    build[A, B, C]("foo")

type
    Bar = object
    Baz = object

discard buildThing[Bar, Baz, 1]()

Additional Information

> nim -v
Nim Compiler Version 0.19.4 [Linux: amd64]
Compiled at 2019-02-01
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: b6d96cafc8bcad1f3d32f2910b25cd11a93f7751
active boot switches: -d:release
@bung87
Copy link
Collaborator

bung87 commented Sep 24, 2022

after debugging make the first error dispear, it runs into instantiateGenericParamList which remain static int literal type , then goes into semAsgn case a.kind else branch, semExprWithType case n.kind of nkCall then it goes to

elif (n[0].kind == nkBracketExpr or shouldBeBracketExpr(n)) and
       isSymChoice(n[0][0]):

before the final fix
I get t10833.nim(7, 19) Error: type mismatch: got <Foo[t10833.Bar, t10833.Baz, system.int]> but expected 'Foo[t10833.Bar, t10833.Baz, 1]'
well, change the return type to auto, it just works fine.
hope I'll fix this soon.

bung87 added a commit to bung87/Nim that referenced this issue Sep 24, 2022
bung87 added a commit to bung87/Nim that referenced this issue Sep 25, 2022
bung87 added a commit to bung87/Nim that referenced this issue Sep 26, 2022
bung87 added a commit to bung87/Nim that referenced this issue Sep 26, 2022
bung87 pushed a commit to bung87/Nim that referenced this issue May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants