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 error on a generic object with an array field #18210

Open
ZoomRmc opened this issue Jun 7, 2021 · 2 comments
Open

Compiler error on a generic object with an array field #18210

ZoomRmc opened this issue Jun 7, 2021 · 2 comments

Comments

@ZoomRmc
Copy link
Contributor

ZoomRmc commented Jun 7, 2021

Compiler error on a generic object with an array field.

Can't use int for L in the following example, so passed a range to satisfy the compiler:

Example

type Foo[L, T] = object
  data: array[L, T]

let p = Foo[0..2, char](data:['a', 'b', 'c'])
#let q = Foo[3, char](data:['a', 'b', 'c']) # type mismatch error

Current Output

Error: internal error: invalid kind for lastOrd(tyObject)
Traceback (most recent call last)
/home/user/.choosenim/toolchains/nim-#devel/compiler/nim.nim(125) nim
/home/user/.choosenim/toolchains/nim-#devel/compiler/nim.nim(84) handleCmdLine
/home/user/.choosenim/toolchains/nim-#devel/compiler/main.nim(274) mainCommand
/home/user/.choosenim/toolchains/nim-#devel/compiler/main.nim(244) compileToBackend
/home/user/.choosenim/toolchains/nim-#devel/compiler/main.nim(100) commandCompileToC
/home/user/.choosenim/toolchains/nim-#devel/compiler/modules.nim(178) compileProject
/home/user/.choosenim/toolchains/nim-#devel/compiler/modules.nim(97) compileModule
/home/user/.choosenim/toolchains/nim-#devel/compiler/passes.nim(180) processModule
/home/user/.choosenim/toolchains/nim-#devel/compiler/passes.nim(73) processTopLevelStmt
/home/user/.choosenim/toolchains/nim-#devel/compiler/sem.nim(627) myProcess
/home/user/.choosenim/toolchains/nim-#devel/compiler/sem.nim(595) semStmtAndGenerateGenerics
/home/user/.choosenim/toolchains/nim-#devel/compiler/semstmts.nim(2310) semStmt
/home/user/.choosenim/toolchains/nim-#devel/compiler/semexprs.nim(1057) semExprNoType
/home/user/.choosenim/toolchains/nim-#devel/compiler/semexprs.nim(2935) semExpr
/home/user/.choosenim/toolchains/nim-#devel/compiler/semstmts.nim(2252) semStmtList
/home/user/.choosenim/toolchains/nim-#devel/compiler/semexprs.nim(2938) semExpr
/home/user/.choosenim/toolchains/nim-#devel/compiler/semstmts.nim(515) semVarOrLet
/home/user/.choosenim/toolchains/nim-#devel/compiler/semexprs.nim(86) semExprWithType
/home/user/.choosenim/toolchains/nim-#devel/compiler/semexprs.nim(70) semExprCheck
/home/user/.choosenim/toolchains/nim-#devel/compiler/semexprs.nim(2901) semExpr
/home/user/.choosenim/toolchains/nim-#devel/compiler/semobjconstr.nim(401) semObjConstr
/home/user/.choosenim/toolchains/nim-#devel/compiler/semobjconstr.nim(334) semConstructTypeAux
/home/user/.choosenim/toolchains/nim-#devel/compiler/semobjconstr.nim(167) semConstructFields
/home/user/.choosenim/toolchains/nim-#devel/compiler/semobjconstr.nim(322) semConstructFields
/home/user/.choosenim/toolchains/nim-#devel/compiler/semobjconstr.nim(82) semConstrField
/home/user/.choosenim/toolchains/nim-#devel/compiler/sem.nim(94) fitNode
/home/user/.choosenim/toolchains/nim-#devel/compiler/semcall.nim(477) indexTypesMatch
/home/user/.choosenim/toolchains/nim-#devel/compiler/sigmatch.nim(2207) paramTypesMatch
/home/user/.choosenim/toolchains/nim-#devel/compiler/sigmatch.nim(2051) paramTypesMatchAux
/home/user/.choosenim/toolchains/nim-#devel/compiler/sigmatch.nim(1232) typeRel
/home/user/.choosenim/toolchains/nim-#devel/compiler/types.nim(847) lengthOrd
/home/user/.choosenim/toolchains/nim-#devel/compiler/types.nim(800) lastOrd
/home/user/.choosenim/toolchains/nim-#devel/compiler/types.nim(808) lastOrd
/home/user/.choosenim/toolchains/nim-#devel/compiler/msgs.nim(600) internalErrorImpl
/home/user/.choosenim/toolchains/nim-#devel/compiler/msgs.nim(556) liMessage
/home/user/.choosenim/toolchains/nim-#devel/compiler/msgs.nim(414) handleError
/home/user/.choosenim/toolchains/nim-#devel/compiler/msgs.nim(403) quit
FAILURE
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-06-07
Copyright (c) 2006-2021 by Andreas Rumpf

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

Possibly related to #17423?

@metagn
Copy link
Collaborator

metagn commented Sep 28, 2024

Same issue as #23204, shouldn't crash anymore but gives another error, the issue is 3 becomes the type int

@metagn
Copy link
Collaborator

metagn commented Oct 14, 2024

Now the 0..2 version doesn't work because it becomes a Slice[int] but range[0..2] works

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

2 participants