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

if nil == X crashes the compiler #23534

Open
PMunch opened this issue Apr 24, 2024 · 1 comment
Open

if nil == X crashes the compiler #23534

PMunch opened this issue Apr 24, 2024 · 1 comment

Comments

@PMunch
Copy link
Contributor

PMunch commented Apr 24, 2024

Description

Fairly simple, passed some C code through c2nim and it spat out some if nil == X statements. These statements unfortunately crash the compiler with Error: internal error: getTypeDescAux(tyGenericParam) so figuring out what was wrong was a bit annoying. It works if typeof(X) is pointer, but crashes if it is for example ptr int.

Nim Version

Nim Compiler Version 2.0.4 [Linux: amd64]
Compiled at 2024-03-28
Copyright (c) 2006-2023 by Andreas Rumpf

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

Current Output

Error: internal error: getTypeDescAux(tyGenericParam)

Expected Output

Some kind of error message explaining that it can't infer the type.

Possible Solution

No response

Additional Information

var x: ptr int

if nil == x: # Crashes the compiler
  echo "X is nil!"
@metagn
Copy link
Collaborator

metagn commented Apr 24, 2024

Same issue as #16148 (though this is only realized after 15 comments), related is #15154 but this is a simpler case of just proc foo[T](a, b: ptr T).

If nil is matching ptr T and resolving T to itself (i.e. T = T vs T = nil) or stopping the resolution of T in some other simple way then this should be fixable (isGeneric?), but if T is being resolved to int and the type of the nil parameter is not populated after the fact then this is a limitation and we need to detect if we assign an unresolved type to a position that won't be populated with resolved parameters later.

Very easy bandaid is:

proc `==`[T](a: typeof(nil) | typeof(nil), b: T) {.magic: "WhateverMagicPointerEqualityUses".}

but in general typeof(nil) | typeof(nil) is a hack and there is a chance this is easy to fix in the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants