-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
checker: fix return type of alias primitive operator overloading #21663
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b493e2
checker: warn on unused imported functions used via `import math { si…
Delta456 0d1113c
Revert "checker: warn on unused imported functions used via `import m…
Delta456 97a10ac
checker: fix return type of alias primitive operator overloading
Delta456 53b788e
attempt to fix tests
Delta456 cac4fdc
fix even more tests
Delta456 1926dc8
combines tests and add more cases
Delta456 925bb2a
fmt
Delta456 48c2efe
Apply suggestions from code review
spytheman 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
type Alias = u8 | ||
|
||
fn new_alias() Alias { | ||
return 0 | ||
} | ||
|
||
fn (a Alias) add(b Alias) Alias { | ||
return new_alias() | ||
} | ||
|
||
fn (a Alias) mul(b Alias) Alias { | ||
return new_alias() | ||
} | ||
|
||
fn (a Alias) + (b Alias) Alias { | ||
return a.add(b) | ||
} | ||
|
||
fn (a Alias) * (b Alias) Alias { | ||
return a.mul(b) | ||
} | ||
|
||
fn test_alias_primitive_operator_overloading() { | ||
a := new_alias() | ||
b := new_alias() | ||
|
||
c := a + b | ||
d := a.add(b) | ||
assert typeof(c).name == 'Alias' | ||
assert typeof(d).name == 'Alias' | ||
|
||
e := a * b | ||
f := a.mul(b) | ||
assert typeof(e).name == 'Alias' | ||
assert typeof(f).name == 'Alias' | ||
} | ||
|
||
type AF_ARRAY = voidptr | ||
|
||
fn (a AF_ARRAY) add(b AF_ARRAY) AF_ARRAY { | ||
mut y := AF_ARRAY(0) | ||
return y | ||
} | ||
|
||
fn (a AF_ARRAY) mul(b AF_ARRAY) AF_ARRAY { | ||
mut y := AF_ARRAY(0) | ||
return y | ||
} | ||
|
||
fn (a AF_ARRAY) + (b AF_ARRAY) AF_ARRAY { | ||
return a.add(b) | ||
} | ||
|
||
fn (a AF_ARRAY) * (b AF_ARRAY) AF_ARRAY { | ||
return a.mul(b) | ||
} | ||
|
||
fn test_alias_voidptr_operator_overloading() { | ||
a := AF_ARRAY(0) | ||
b := AF_ARRAY(0) | ||
|
||
c := a + b | ||
y := a * a | ||
|
||
assert c == a.add(b) | ||
assert y == a.mul(a) | ||
|
||
assert typeof(c).name == 'AF_ARRAY' | ||
assert typeof(y).name == 'AF_ARRAY' | ||
} |
Oops, something went wrong.
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.
please add comments for such large code blocks to explain what they are for
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.
ok! will add this in my next PR