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 new warning when nil is assigned to a non-nilable type #649

Closed
wants to merge 1 commit into from

Conversation

Hazematman
Copy link

This pull request add a new warning when you assign nil to a type that is not-nilable. For example the following code

local x: number = 10
x = nil

will now return an warning that looks like

========================================
1 warning:
test.tl:18:1: assigning nil to a non-nilable type number

hinting that the correct way to write this code is (assuming that you want assigning nil to be valid)

local x: number | nil = 10
x = nil

This change causes the tl compiler to throw a lot of warning when building. If required I could modify the tl compiler to explicitly mark types as nilable where required.

This change also required a test update to the record function spec tests, as one of the tests would assign nil to a boolean value and then expect zero warning to be generated.

@github-actions
Copy link

Teal Playground URL: https://649--teal-playground-preview.netlify.app

@Hazematman
Copy link
Author

Closing this PR as it only address one issue surrounding nil ability of types. Proper nil checking would require more changes to the type system.

@Hazematman Hazematman closed this Apr 24, 2023
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

1 participant