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

Calling typeof on in-place constructed empty object crashes compiler #24751

Open
bptato opened this issue Mar 5, 2025 · 1 comment · May be fixed by #24752
Open

Calling typeof on in-place constructed empty object crashes compiler #24751

bptato opened this issue Mar 5, 2025 · 1 comment · May be fixed by #24752

Comments

@bptato
Copy link
Contributor

bptato commented Mar 5, 2025

Nim Version

Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-03-05
Copyright (c) 2006-2025 by Andreas Rumpf

git hash: 569d02e
active boot switches:

Description

Following code crashes the compiler.

type A = object

var a: typeof(A())

Current Output

/src/Nim/compiler/nim.nim(169) nim
/src/Nim/compiler/nim.nim(124) handleCmdLine
/src/Nim/compiler/main.nim(307) mainCommand
/src/Nim/compiler/main.nim(274) compileToBackend
/src/Nim/compiler/main.nim(137) commandCompileToC
/src/Nim/compiler/pipelines.nim(311) compilePipelineProject
/src/Nim/compiler/pipelines.nim(231) compilePipelineModule
/src/Nim/compiler/pipelines.nim(178) processPipelineModule
/src/Nim/compiler/pipelines.nim(25) processPipeline
/src/Nim/compiler/cgen.nim(2430) genTopLevelStmt
/src/Nim/compiler/injectdestructors.nim(1268) injectDestructorCalls
/src/Nim/compiler/optimizer.nim(284) optimize
/src/Nim/compiler/optimizer.nim(237) analyse
/src/Nim/compiler/optimizer.nim(237) analyse
/src/Nim/compiler/optimizer.nim(237) analyse
/src/Nim/compiler/optimizer.nim(237) analyse
/src/Nim/compiler/optimizer.nim(237) analyse
/src/Nim/compiler/optimizer.nim(131) analyse
/src/Nim/compiler/optimizer.nim(146) analyse
/src/Nim/compiler/ast.nim(2094) canRaise
/src/Nim/lib/system/fatal.nim(53) sysFatal
Error: unhandled exception: index out of bounds, the container is empty [IndexDefect]

Expected Output

Compiles.

Known Workarounds

No response

Additional Information

No response

metagn added a commit to metagn/Nim that referenced this issue Mar 5, 2025
@metagn metagn linked a pull request Mar 5, 2025 that will close this issue
@metagn
Copy link
Collaborator

metagn commented Mar 5, 2025

Happens since 2.0

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

Successfully merging a pull request may close this issue.

2 participants