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

distinct object type definition crashes the compiler #1434

Open
zerbina opened this issue Aug 27, 2024 · 1 comment
Open

distinct object type definition crashes the compiler #1434

zerbina opened this issue Aug 27, 2024 · 1 comment
Labels
bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler

Comments

@zerbina
Copy link
Collaborator

zerbina commented Aug 27, 2024

Example

type Type = distinct object

var x = default(Type)

Actual Output

The compiler crashes:

SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Expected Output

A proper compiler error about distinct object not being a valid type.

Additional Information

The crash is due to the object part resulting in an incomplete tyObject type instance. Among other things, it's missing a symbol, violating the invariant of tyObject always having a symbol attached, thus crashing the compiler once the symbol is attempted to be accessed.

There are two problems here:

  1. object as it's used here doesn't construct a tyObject type, but instead names the built-in object type-class (i.e., (BuiltInTypeClass (Object))). The logic in semtypes.semObjectNode doesn't handle this properly.

  2. distinct T where T is a type-class is only valid in a routine parameter or generic parameter position, but there's nothing enforcing this.

References

The issue was discovered with the cps test suite and reported by @alaviss on Matrix.

@zerbina zerbina added bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler labels Aug 27, 2024
@zerbina zerbina self-assigned this Aug 27, 2024
@zerbina
Copy link
Collaborator Author

zerbina commented Aug 29, 2024

It's not yet clear what distinct object in a type definition should mean. My preference is that it should mean the same as in a usage context (i.e., type-class), whereas @alaviss argues that it should be a shorthand for object type definition + distinct type construction (similar to how ref object and ptr object work).

The discussion so far can be found here.

@zerbina zerbina removed their assignment Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler
Projects
None yet
Development

No branches or pull requests

1 participant