-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
cgen: allow assignment operators for type aliases #8086
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d6d1cbf
cgen: allow assignment operators for type alias
Delta456 8c6e87c
remove extra space
Delta456 22eb988
more work
Delta456 3ca4f34
oops
Delta456 399bcd1
oops x2
Delta456 ce9a2f7
fix ci
Delta456 ed639ef
fmt
Delta456 bea792b
more progress, doesnt works
Delta456 50a1af1
remove println
danieldaeschle 7f70ca5
make checker accept test cases
danieldaeschle 43c7c9f
simplify something
danieldaeschle 130a87d
rewrite
Delta456 97c62cf
fmt
Delta456 243e914
remove
Delta456 d40c245
new message
Delta456 c809c82
remove
Delta456 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,42 @@ | ||
| vlib/v/checker/tests/method_op_alias_err.vv:4:1: error: both sides of an operator must be the same type | ||
| 2 | type Foo2 = string | ||
| 3 | | ||
| 4 | fn (f Foo) + (f1 Foo2) Foo2 { | ||
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 5 | return Foo2(f + f1) | ||
| 6 | } | ||
| vlib/v/checker/tests/method_op_alias_err.vv:5:19: error: infix expr: cannot use `string` (right expression) as `string` | ||
Delta456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 3 | | ||
| 4 | fn (f Foo) + (f1 Foo2) Foo2 { | ||
| 5 | return Foo2(f + f1) | ||
| | ^ | ||
| 6 | } | ||
| 7 | | ||
| vlib/v/checker/tests/method_op_alias_err.vv:8:1: error: cannot define operator methods on type alias for `string` | ||
| 6 | } | ||
| 7 | | ||
| 8 | fn (f Foo) * (f1 Foo) Foo { | ||
| | ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 9 | return Foo(f + f1) | ||
| 10 | } | ||
| vlib/v/checker/tests/method_op_alias_err.vv:14:6: error: mismatched types `Foo` and `string` | ||
| 12 | fn main() { | ||
| 13 | mut f := Foo('fg') | ||
| 14 | f += 'fg' | ||
| | ~~ | ||
| 15 | f *= Foo2('2') | ||
| 16 | f -= Foo('fo') | ||
| vlib/v/checker/tests/method_op_alias_err.vv:15:9: error: cannot assign to `f`: expected `Foo`, not `Foo2` | ||
| 13 | mut f := Foo('fg') | ||
| 14 | f += 'fg' | ||
| 15 | f *= Foo2('2') | ||
| | ~~~~~~~~~ | ||
| 16 | f -= Foo('fo') | ||
| 17 | println(f) | ||
| vlib/v/checker/tests/method_op_alias_err.vv:16:6: error: cannot use operator methods on type alias for `string` | ||
| 14 | f += 'fg' | ||
| 15 | f *= Foo2('2') | ||
| 16 | f -= Foo('fo') | ||
| | ~~ | ||
| 17 | println(f) | ||
| 18 | } | ||
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,18 @@ | ||
| type Foo = string | ||
| type Foo2 = string | ||
|
|
||
| fn (f Foo) + (f1 Foo2) Foo2 { | ||
| return Foo2(f + f1) | ||
| } | ||
|
|
||
| fn (f Foo) * (f1 Foo) Foo { | ||
| return Foo(f + f1) | ||
| } | ||
|
|
||
| fn main() { | ||
| mut f := Foo('fg') | ||
| f += 'fg' | ||
| f *= Foo2('2') | ||
| f -= Foo('fo') | ||
| println(f) | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.