Skip to content

Type classes with type parameters don't work very well #517

@ghost

Description

type
  TVecT*[T] = array[0..1, T]|array[0..2, T]|array[0..3, T]
  TVec2* = array[0..1, float32]

proc f[T](a: TVecT[T], b: TVecT[T]): T = discard

#f([0.0'f32, 0.0'f32], [0.0'f32, 0.0'f32])
#f(TVec2([0.0'f32, 0.0'f32]), TVec2([0.0'f32, 0.0'f32]))

Uncommenting the first call to 'f' results in this:

type_param_bug.nim(7, 2) Error: type mismatch: got (Array constructor[0..1, float32], Array constructor[0..1, float32])
**but expected one of: **
type_param_bug.f(a: TVecT[T], b: TVecT[T]): T

and the second call (which isn't valid code) gives me an ICE:

Error: internal error: wrong instantiated type!
Traceback (most recent call last)
nimrod.nim(79) nimrod
nimrod.nim(55) HandleCmdLine
main.nim(487) MainCommand
main.nim(256) CommandCompileToC
main.nim(210) CompileProject
main.nim(168) compileModule
passes.nim(192) processModule
passes.nim(136) processTopLevelStmt
sem.nim(300) myProcess
sem.nim(274) SemStmtAndGenerateGenerics
semstmts.nim(1238) semStmt
semexprs.nim(777) semExprNoType
semexprs.nim(1841) semExpr
semexprs.nim(720) semDirectOp
semexprs.nim(619) semOverloadedCallAnalyseEffects
semcall.nim(156) semOverloadedCall
semcall.nim(66) resolveOverloads
sigmatch.nim(1026) matches
sigmatch.nim(995) matchesAux
sigmatch.nim(816) ParamTypesMatch
sigmatch.nim(746) ParamTypesMatchAux
sigmatch.nim(607) typeRel
msgs.nim(786) InternalError
msgs.nim(724) rawMessage
msgs.nim(721) rawMessage
msgs.nim(674) handleError

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions