-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Improve error messages for invalid property access/calls in GDScript #46241
Closed
Calinou
wants to merge
1
commit into
godotengine:master
from
Calinou:improve-gdscript-invalid-access-error-messages
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -808,7 +808,11 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a | |
} else { | ||
v = "of type '" + _get_var_type(index) + "'"; | ||
} | ||
err_text = "Invalid get index " + v + " (on base: '" + _get_var_type(src) + "')."; | ||
if (!src->is_null()) { | ||
err_text = "Tried to access attribute " + v + " on a value that is null."; | ||
} else { | ||
err_text = "Value of type '" + _get_var_type(src) + "' does not have the attribute " + v + "."; | ||
} | ||
Comment on lines
+811
to
+815
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the condition backwards here? |
||
OPCODE_BREAK; | ||
} | ||
*dst = ret; | ||
|
@@ -844,7 +848,11 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a | |
} else { | ||
v = "of type '" + _get_var_type(key) + "'"; | ||
} | ||
err_text = "Invalid get index " + v + " (on base: '" + _get_var_type(src) + "')."; | ||
if (!src->is_null()) { | ||
err_text = "Tried to access attribute " + v + " on a value that is null."; | ||
} else { | ||
err_text = "Value of type '" + _get_var_type(src) + "' does not have the attribute " + v + "."; | ||
} | ||
OPCODE_BREAK; | ||
} | ||
*dst = ret; | ||
|
@@ -947,9 +955,17 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a | |
#ifdef DEBUG_ENABLED | ||
if (!valid) { | ||
if (src->has_method(*index)) { | ||
err_text = "Invalid get index '" + index->operator String() + "' (on base: '" + _get_var_type(src) + "'). Did you mean '." + index->operator String() + "()' or funcref(obj, \"" + index->operator String() + "\") ?"; | ||
if (!src->is_null()) { | ||
err_text = "Tried to access attribute '" + index->operator String() + "' on a value that is null. Did you mean '." + index->operator String() + "()' or funcref(obj, \"" + index->operator String() + "\") ?"; | ||
} else { | ||
err_text = "Value of type '" + _get_var_type(src) + "' does not have the attribute '" + index->operator String() + "'. Did you mean '." + index->operator String() + "()' or funcref(obj, \"" + index->operator String() + "\") ?"; | ||
} | ||
} else { | ||
err_text = "Invalid get index '" + index->operator String() + "' (on base: '" + _get_var_type(src) + "')."; | ||
if (!src->is_null()) { | ||
err_text = "Tried to access attribute '" + index->operator String() + "' on a value that is null."; | ||
} else { | ||
err_text = "Value of type '" + _get_var_type(src) + "' does not have the attribute '" + index->operator String() + "'."; | ||
} | ||
} | ||
OPCODE_BREAK; | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have information about what identifier is of type Nil? Or would that be explicit enough from the stacktrace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder why the
keywordliteral isnull
and its name isnil
. They have different meanings in some other languages (like Objective C, Scala). In general, NULL is 0 or'\0'
in ASCII and Nil is emptiness. (I'd like it asnull
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this in a GDScript meeting and suggest indeed referring to
null
directly. Maybe this could be:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or the same phrasing as used in your VM changes to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which changes are you referring to? I may have forgotten something 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the sentence you used for the null case in
gdscript_vm.cpp
: