-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx Interop] Disambiguate methods within the same class with same name but differing "constness" #41308
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
Merged
Merged
[cxx Interop] Disambiguate methods within the same class with same name but differing "constness" #41308
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f8f8e16
Start with writing failing tests
Huddie 18c6bdd
[Cxx iterop] Disambiguate between methods with the same name but diff…
Huddie 6f93bc8
Remove required failure on windows for tests
Huddie f3f75ba
Change order of const/mutable in class to enhance test
Huddie 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 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef TEST_INTEROP_CXX_CLASS_AMBIGUOUS_METHOD_METHODS_H | ||
#define TEST_INTEROP_CXX_CLASS_AMBIGUOUS_METHOD_METHODS_H | ||
|
||
struct HasAmbiguousMethods { | ||
|
||
// No input | ||
void ping() { ++mutableMethodsCalledCount; } | ||
void ping() const {} | ||
|
||
// One input (const first) | ||
int increment(int a) const { | ||
return a + 1; | ||
} | ||
|
||
int increment(int a) { | ||
++mutableMethodsCalledCount; | ||
return a + 1; | ||
} | ||
|
||
// Multiple input with out param | ||
void increment(int a, int b, int &c) { | ||
++mutableMethodsCalledCount; | ||
c = a + b; | ||
} | ||
|
||
void increment(int a, int b, int &c) const { | ||
c = a + b; | ||
} | ||
|
||
// Multiple input with inout param | ||
void increment(int &a, int b) { | ||
++mutableMethodsCalledCount; | ||
a += b; | ||
} | ||
|
||
void increment(int &a, int b) const { | ||
a += b; | ||
} | ||
|
||
// No input with output (const first) | ||
int numberOfMutableMethodsCalled() const { return mutableMethodsCalledCount; } | ||
int numberOfMutableMethodsCalled() { return ++mutableMethodsCalledCount; } | ||
|
||
private: | ||
int mutableMethodsCalledCount = 0; | ||
}; | ||
|
||
#endif // TEST_INTEROP_CXX_CLASS_AMBIGUOUS_METHOD_METHODS_H |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
module Methods { | ||
header "methods.h" | ||
requires cplusplus | ||
} | ||
|
||
module AmbiguousMethods { | ||
header "ambiguous_methods.h" | ||
requires cplusplus | ||
} |
16 changes: 16 additions & 0 deletions
16
test/Interop/Cxx/class/method/ambiguous-methods-module-interface.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// RUN: %target-swift-ide-test -print-module -module-to-print=AmbiguousMethods -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s | ||
|
||
// CHECK: mutating func pingMutating() | ||
// CHECK: func ping() | ||
|
||
// CHECK: func increment(_ a: Int32) -> Int32 | ||
// CHECK: mutating func incrementMutating(_ a: Int32) -> Int32 | ||
|
||
// CHECK: mutating func incrementMutating(_ a: Int32, _ b: Int32, _ c: inout Int32) | ||
// CHECK: func increment(_ a: Int32, _ b: Int32, _ c: inout Int32) | ||
|
||
// CHECK: mutating func incrementMutating(_ a: inout Int32, _ b: Int32) | ||
// CHECK: func increment(_ a: inout Int32, _ b: Int32) | ||
|
||
// CHECK: func numberOfMutableMethodsCalled() -> Int32 | ||
// CHECK: mutating func numberOfMutableMethodsCalledMutating() -> Int32 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-cxx-interop) | ||
// | ||
// REQUIRES: executable_test | ||
// | ||
|
||
import StdlibUnittest | ||
import AmbiguousMethods | ||
|
||
var CxxAmbiguousMethodTestSuite = TestSuite("CxxAmbiguousMethods") | ||
|
||
CxxAmbiguousMethodTestSuite.test("numberOfMutableMethodsCalled: () -> Int") { | ||
var instance = HasAmbiguousMethods() | ||
|
||
// Sanity check. Make sure we start at 0 | ||
expectEqual(0, instance.numberOfMutableMethodsCalled()) | ||
|
||
// Make sure calling numberOfMutableMethodsCalled above didn't | ||
// change the count | ||
expectEqual(0, instance.numberOfMutableMethodsCalled()) | ||
|
||
// Check that mutable version _does_ change the mutable call count | ||
expectEqual(1, instance.numberOfMutableMethodsCalledMutating()) | ||
|
||
expectEqual(1, instance.numberOfMutableMethodsCalled()) | ||
} | ||
|
||
CxxAmbiguousMethodTestSuite.test("Basic Increment: (Int) -> Int") { | ||
var instance = HasAmbiguousMethods() | ||
var a: Int32 = 0 | ||
|
||
// Sanity check. Make sure we start at 0 | ||
expectEqual(0, instance.numberOfMutableMethodsCalled()) | ||
|
||
// Non mutable version should NOT change count | ||
a = instance.increment(a); | ||
expectEqual(1, a) | ||
expectEqual(0, instance.numberOfMutableMethodsCalled()) | ||
|
||
a = instance.incrementMutating(a); | ||
expectEqual(2, a) | ||
expectEqual(1, instance.numberOfMutableMethodsCalled()) | ||
} | ||
|
||
CxxAmbiguousMethodTestSuite.test("Out Param Increment: (Int, Int, inout Int) -> Void") { | ||
var instance = HasAmbiguousMethods() | ||
var out: Int32 = 0 | ||
|
||
// Sanity check. Make sure we start at 0 | ||
expectEqual(0, instance.numberOfMutableMethodsCalled()) | ||
|
||
// Non mutable version should NOT change count | ||
instance.increment(0, 1, &out); | ||
expectEqual(1, out) | ||
expectEqual(0, instance.numberOfMutableMethodsCalled()) | ||
|
||
instance.incrementMutating(5, 2, &out); | ||
expectEqual(7, out) | ||
expectEqual(1, instance.numberOfMutableMethodsCalled()) | ||
} | ||
|
||
CxxAmbiguousMethodTestSuite.test("Inout Param Increment: (inout Int, Int) -> Void") { | ||
var instance = HasAmbiguousMethods() | ||
var inoutVal: Int32 = 0 | ||
|
||
// Sanity check. Make sure we start at 0 | ||
expectEqual(0, instance.numberOfMutableMethodsCalled()) | ||
|
||
// Non mutable version should NOT change count | ||
instance.increment(&inoutVal, 1); | ||
expectEqual(1, inoutVal) | ||
expectEqual(0, instance.numberOfMutableMethodsCalled()) | ||
|
||
instance.incrementMutating(&inoutVal, 2); | ||
expectEqual(3, inoutVal) | ||
expectEqual(1, instance.numberOfMutableMethodsCalled()) | ||
} | ||
|
||
runAllTests() |
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
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.
It looks like your test cases are in a pattern of:
Could you also add another method pair in reverse order, i.e.
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.
Great idea!