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 internal error on iterator it(T: typedesc[Base]) called with it(Child), where Child = object of Base #2662

Closed
nanoant opened this issue May 6, 2015 · 0 comments

Comments

@nanoant
Copy link
Member

nanoant commented May 6, 2015

Following IMHO valid code crashes latest Nim compiler 0.11.2 with internal error.

Since using 1st arg of typedesc[ClassName] is proper way to define class methods (not instance methods) making this work is pretty important.

import typetraits

type
  Base = object of RootObj
  Child = object of Base

proc pr(T: typedesc[Base]) = echo "call from " & T.name

iterator it(T: typedesc[Base]) = yield "yield from " & T.name

Base.pr
Child.pr

for s in Base.it: echo s
for s in Child.it: echo s # <- internal error: getUniqueType

Commenting out last line makes everything work well, so the bug applies only to iterators.

Full error stack:

Error: internal error: getUniqueType
Traceback (most recent call last)
nim.nim(94)              nim
nim.nim(56)              handleCmdLine
main.nim(252)            mainCommand
main.nim(63)             commandCompileToC
modules.nim(203)         compileProject
modules.nim(151)         compileModule
passes.nim(197)          processModule
passes.nim(137)          processTopLevelStmt
cgen.nim(1210)           myProcess
ccgstmts.nim(1111)       genStmts
ccgexprs.nim(2075)       expr
ccgstmts.nim(1111)       genStmts
ccgexprs.nim(2072)       expr
ccgstmts.nim(502)        genBlock
ccgexprs.nim(2075)       expr
ccgstmts.nim(1111)       genStmts
ccgexprs.nim(2075)       expr
ccgstmts.nim(1111)       genStmts
ccgexprs.nim(2094)       expr
ccgstmts.nim(259)        genVarStmt
ccgstmts.nim(237)        genSingleVar
cgen.nim(404)            assignLocalVar
cgen.nim(389)            localVarDecl
ccgtypes.nim(693)        getTypeDesc
ccgtypes.nim(528)        getTypeDescAux
ccgutils.nim(102)        getUniqueType
msgs.nim(849)            internalError
msgs.nim(771)            rawMessage
msgs.nim(768)            rawMessage
msgs.nim(715)            handleError
nanoant added a commit to nanoant/Nim that referenced this issue May 13, 2015
There is no point to issue implicit HiddenStdConv encountering subtype of
typedesc[Base] parameter on overload resolution, since this will anyway never
reach codegen. This change effectively fixes compiler bug for:

  iterator it(T: typedesc[Base]) = ...
  for s in it(SubclassOfBase): ...

Where HiddenStdConv triggered implicit instantiation of variable of type
typedesc[Base] in for transform, that eventually fails at getUniqueType, that
refuses to work for typedesc.
nanoant added a commit to nanoant/Nim that referenced this issue May 13, 2015
nanoant added a commit to nanoant/Nim that referenced this issue May 13, 2015
@Araq Araq closed this as completed in 179d82c May 13, 2015
Araq added a commit that referenced this issue May 13, 2015
…desc-params

Fix #2662: Don't convert subtype typedesc params
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

No branches or pull requests

1 participant