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

Add Never type to Prelude (WIP on warning for expressions after a function with return type Never) #3047

Closed
wants to merge 2 commits into from

Conversation

Pi-Cla
Copy link
Contributor

@Pi-Cla Pi-Cla commented Apr 26, 2024

As discussed in #3044 it would be neat to add a type to the Prelude which could represent functions which never return.

The Never type can not be constructed because if it could be constructed then someone could write a function which does return at some point with it.
For example we don't want this to be possible:

fn go_forever() -> Never {
    // oh no it actually does stop!
    Never
}

WIP on figuring out where to add in the Warning for expressions coming after a function/expression of type Never.

The Never type can't be constructed so it can represent functions that never return. Spooky!
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thank you but it cannot be implemented as a named type as it has different semantics to them. It needs to be a super type of all other types, otherwise panic would be too restrictive and not usable in case expressions.

It's probably worth writing down what the design is before implementation as it'll be quicker to iterate on how it works that way. This will be the most complex change to the type system in some time.

@Pi-Cla
Copy link
Contributor Author

Pi-Cla commented Apr 27, 2024

I see... then I guess I will just mark this as a draft for now and wait until a final design has been decided on. (This PR can also just be closed if it is taking up space)

@Pi-Cla Pi-Cla marked this pull request as draft April 27, 2024 07:45
@lpil
Copy link
Member

lpil commented May 20, 2024

Closing due to inactivity. Please feel free to reopen! Thank you

@lpil lpil closed this May 20, 2024
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 this pull request may close these issues.

None yet

2 participants