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

(interpreter) Make operand type checks be compile-time errors #329

Merged
merged 1 commit into from
May 11, 2022

Conversation

perlun
Copy link
Collaborator

@perlun perlun commented May 10, 2022

This greatly improves the developer experience. It involves a bit of duplication, but the duplication is more or less inevitable in this case.

@perlun perlun added enhancement New feature or request language Language features (or bugs) labels May 10, 2022
@perlun perlun added this to the 0.2.0 milestone May 10, 2022
@@ -904,6 +904,7 @@ private static void CheckNumberOperands(Token @operator, object? left, object? r
return;
}

// TODO: Why does this still happen?
throw new RuntimeError(@operator, $"Operands must be numbers, not {StringifyType(left)} and {StringifyType(right)}");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are still some tests which make assertions on this (runtime) error, which puzzles me a bit. I'll look into this a bit further before getting this merged.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I get it now... This is a bit hairy. 🙈 Here's an example test that will trigger this:

fun greet(name: string, age: int): void {
  print "Hello " + name + ". Your age is " + age;
}

// Expected warning: [line 6] Warning at 'name': Null parameter detected
greet(null, 42);

The above is understood as string + string, but string + null will cause the exception above. This is not ideal; I filed a new bug about it now: #330.

@perlun perlun force-pushed the fix/make-type-checks-validation-errors branch from 896274f to e71f87d Compare May 11, 2022 17:57
@perlun perlun enabled auto-merge (squash) May 11, 2022 17:58
@perlun perlun merged commit de3ff2e into master May 11, 2022
@perlun perlun deleted the fix/make-type-checks-validation-errors branch May 11, 2022 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request language Language features (or bugs)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant