Fix prototype call check for nullable types#1230
Merged
Conversation
aSemy
reviewed
Mar 13, 2022
| // Issue #1218: https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1218 | ||
| test.each(['"foo"', "undefined"])("prototype call on nullable string (%p)", value => { | ||
| util.testFunction` | ||
| function toUpper(str?: string) { |
There was a problem hiding this comment.
str?: string is one way of triggering the bug in #1218 - Is it also worth having tests for the other potential triggers, str: string | undefined and str: string | null? I only see tests for str?: string.
Member
Author
There was a problem hiding this comment.
They should all resolve to the same type (kinda), but you are right, adding some more tests wouldn't hurt. I added some more.
lolleko
approved these changes
Mar 17, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Turns out that when we check for built-in prototype methods (like
string.prototype.substringfor example), we were not taking optional chaining into account. ThereforestrOrUndefined?.substring()would lead to invalid Lua. This PR fixes the check for all prototype calls we detect, so they also work in case of optional chaining.Fixes #1218