-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
some fixes to method ambiguity reflection #16220
Merged
Merged
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
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 |
---|---|---|
|
@@ -24,7 +24,8 @@ for m in mt | |
end | ||
|
||
@test length(methods(ambig, (Int, Int))) == 1 | ||
@test length(methods(ambig, (UInt8, Int))) == 2 | ||
@test length(methods(ambig, (UInt8, Int))) == 0 | ||
@test length(Base.methods_including_ambiguous(ambig, (UInt8, Int))) == 2 | ||
|
||
@test ambig("hi", "there") == 1 | ||
@test ambig(3.1, 3.2) == 5 | ||
|
@@ -49,8 +50,6 @@ code_native(io, ambig, (Int, Int)) | |
# Test that ambiguous cases fail appropriately | ||
@test precompile(ambig, (UInt8, Int)) == false | ||
cfunction(ambig, Int, (UInt8, Int)) # test for a crash (doesn't throw an error) | ||
@test length(code_lowered(ambig, (UInt8, Int))) == 2 | ||
@test length(code_typed(ambig, (UInt8, Int))) == 2 | ||
@test_throws ErrorException code_llvm(io, ambig, (UInt8, Int)) | ||
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. what's the expected result of these now then? 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. I felt |
||
@test_throws ErrorException code_native(io, ambig, (UInt8, Int)) | ||
|
||
|
@@ -110,4 +109,36 @@ ambs = detect_ambiguities(Ambig4) | |
# Test that Core and Base are free of ambiguities | ||
@test isempty(detect_ambiguities(Core, Base; imported=true)) | ||
|
||
amb_1(::Int8, ::Int) = 1 | ||
amb_1(::Integer, x) = 2 | ||
amb_1(x, ::Int) = 3 | ||
# if there is an ambiguity with some methods and not others, `methods` | ||
# should return just the non-ambiguous ones, i.e. the ones that could actually | ||
# be called. | ||
@test length(methods(amb_1, Tuple{Integer, Int})) == 1 | ||
|
||
amb_2(::Int, y) = 1 | ||
amb_2(x, ::Int) = 2 | ||
amb_2(::Int8, y) = 3 | ||
@test length(methods(amb_2)) == 3 # make sure no duplicates | ||
|
||
amb_3(::Int8, ::Int8) = 1 | ||
amb_3(::Int16, ::Int16) = 2 | ||
amb_3(::Integer, ::Integer) = 3 | ||
amb_3(::Integer, x) = 4 | ||
amb_3(x, ::Integer) = 5 | ||
# ambiguous definitions exist, but are covered by multiple more specific definitions | ||
let ms = methods(amb_3).ms | ||
@test !Base.isambiguous(ms[4], ms[5]) | ||
end | ||
|
||
amb_4(::Int8, ::Int8) = 1 | ||
amb_4(::Int16, ::Int16) = 2 | ||
amb_4(::Integer, x) = 4 | ||
amb_4(x, ::Integer) = 5 | ||
# as above, but without sufficient definition coverage | ||
let ms = methods(amb_4).ms | ||
@test Base.isambiguous(ms[3], ms[4]) | ||
end | ||
|
||
nothing |
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.
+1
alternatively, I've been wondering if we can use the work done here to create a fast-path for
invalidate_conflicting
where we only test lambdas that were derived from methods thatcheck_ambiguous
deemed to have an intersectionThere 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.
This was motivated by the following example:
Here we fail to detect that
Int8, Int
is ambiguous.Yes, that sounds promising.