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

Compiler crash with generic types and static generic parameters #7569

Closed
vincentvidal opened this issue Apr 11, 2018 · 3 comments

Comments

Projects
None yet
5 participants
@vincentvidal
Copy link

commented Apr 11, 2018

This code yields a compiler error:

type
    Expr = object of RootObj
    TemplateExpr[Mutable: static[bool], Composite: static[bool]] = ref object of Expr
        when Mutable:
            dependencies: seq[Expr]
        when Composite:
            components: seq[Expr]

    ValuedExpr[T, Mutable: static[bool], Composite: static[bool]] = ref object of TemplateExpr[Mutable, Composite]
        value: T

The error:

expr.nim(7, 9) Error: internal error: addInheritedFieldsAux()

@zah zah added the Static[T] label Apr 11, 2018

@Yardanico Yardanico added the Crash label Apr 12, 2018

@vincentvidal

This comment has been minimized.

Copy link
Author

commented Apr 13, 2018

Simpler example that leads to the same error:

type
    A[T; cond: static[bool]] = object of RootObj
        when cond:
            x: int
    B[T] = object of A[T, true]

It compiles when removing the T parameter, OR removing the 'when' statement.
This bug is really annoying to me...

@vincentvidal

This comment has been minimized.

Copy link
Author

commented Apr 13, 2018

By luck I found a quick'n dirty hack that seems to work. Very naive though, I cannot pretend to submit a pull request: I really have no knowledge of the internals of the compiler and I probably missed many issues.
In the file compiler/semtypes.nim, in proc addInheritedFieldsAux (line 673), I replaced:

  of nkRecList:
    for i in countup(0, sonsLen(n) - 1):
      addInheritedFieldsAux(c, check, pos, n.sons[i])

by

  of nkRecList, nkRecWhen, nkElifBranch, nkElse:
    for i in countup(0, sonsLen(n) - 1):
      addInheritedFieldsAux(c, check, pos, n.sons[i])

If someone could take a look...

@Araq

This comment has been minimized.

Copy link
Member

commented Apr 13, 2018

That fix is ok. At least it improves the situation.

@Araq Araq added this to the v1 milestone Jun 8, 2018

@narimiran narimiran modified the milestones: v1, v0.20 Feb 15, 2019

narimiran added a commit to narimiran/Nim that referenced this issue May 9, 2019

@Araq Araq closed this in e54546b May 10, 2019

narimiran added a commit that referenced this issue May 10, 2019

fixes #7569, all credit to @vincentvidal (#11213)
(cherry picked from commit e54546b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.