Fix Issue 22159 - == causes error for array of classes in safe method #14988
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.
If the type of classes that are compared does not override
opEquals
,Object.opEquals
ends up, eventually, being called. SinceObject.opEquals
is @System, @safe user code is going to issue a confusing "Incompatible types for comparison: LeClass and LeClass". To fix this, I'm simply checking ifObject.opEquals
is being called and I'm trusting it (it's just doing anis
comparison anyway)."But why aren't you marking
Object.opEquals
as @safe?" -> that will impose the restriction that all classes define a @safe opEquals (which would normally make sense, but it would break tons of code)."This makes the code ugly" -> I agree, but I have no other idea on how to fix this, other than ProtoObject. Maybe other better solutions exist, feel free to enlighten me.
"This does not fix the underlying issue that the compiler gags errors when analyzing the hook, therefore it's still possible to have a confusing error message, for example when a class defines a system opEquals that is called from safe code" -> Yes, but that matter can be explored in a different PR.
cc @adamdruppe as you have been looking at this.