forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: strictly check operator overload ambiguity (AssemblyScript#2762)
Operator overload is an internal mechanism, it can support to compare user-defined class, but it need to be limited. a == b and b == a should run the same function and get the same result in semantic level. Allowing ambiguity is bug prone.
- Loading branch information
1 parent
1847c8f
commit dfc8a65
Showing
10 changed files
with
4,549 additions
and
233 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,14 @@ | ||
{ | ||
"asc_flags": [], | ||
"stderr": [ | ||
"AS240: Ambiguous operator overload '==' (conflicting overloads 'operator-overload-ambiguity/A#__eq' and 'operator-overload-ambiguity/B#__eq').", | ||
"compare_nonnull_a == compare_nonnull_b;", | ||
"AS240: Ambiguous operator overload '==' (conflicting overloads 'operator-overload-ambiguity/B#__eq' and 'operator-overload-ambiguity/A#__eq').", | ||
"compare_nonnull_b == compare_nonnull_a;", | ||
"AS240: Ambiguous operator overload '==' (conflicting overloads 'operator-overload-ambiguity/C.__eq' and 'operator-overload-ambiguity/D#__eq').", | ||
"compare_nonnull_c == compare_nonnull_d;", | ||
"AS240: Ambiguous operator overload '==' (conflicting overloads 'operator-overload-ambiguity/A#__eq' and 'operator-overload-ambiguity/B#__eq').", | ||
"compare_extend_1 == compare_extend_2;", | ||
"EOF" | ||
] | ||
} |
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,38 @@ | ||
class A { | ||
@operator("==") __eq(other: B): bool { | ||
return true; | ||
} | ||
} | ||
class B { | ||
@operator("==") __eq(other: A): bool { | ||
return true; | ||
} | ||
} | ||
export function compare_nonnull(compare_nonnull_a: A, compare_nonnull_b: B): void { | ||
compare_nonnull_a == compare_nonnull_b; | ||
compare_nonnull_b == compare_nonnull_a; | ||
} | ||
|
||
class C { | ||
@operator("==") static __eq(self: C | null, other: D | null): bool { | ||
return true; | ||
} | ||
} | ||
class D { | ||
@operator("==") __eq(other: i32): bool { | ||
return true; | ||
} | ||
} | ||
export function compare_null(compare_nonnull_c: C | null, compare_nonnull_d: D | null): void { | ||
compare_nonnull_c == compare_nonnull_d; | ||
} | ||
|
||
class PA extends A {} | ||
class PB extends B {} | ||
export function compare_extend(compare_extend_1: PA, compare_extend_2: PB): void { | ||
compare_extend_1 == compare_extend_2; | ||
} | ||
|
||
export function end(): void { | ||
ERROR("EOF"); | ||
} |
Oops, something went wrong.