-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler-v2] Revise ability checking for type parameters (#15006)
* [compiler-v2] Revise ability checking for type parameters Closes #14490 Move has some unusual semantics for ability checking of type parameters - In most contexts, a type parameter is assumed to have all abilities during checking. Then when the parameter is instantiated, checking takes place. - However, there is one exemption, namely when a type parameter is used to instantiate another type parameter which has an abilitie constraint, as in `f<T:drop>`. If we instantiate `f<R>` then `R` needs to be checked for `drop`. This PR solves this by adding a field `type_param_exempted` to `HasAbilities(abilities, type_param_exempted)` to the ability constraint. * Adding enum `AbilityCheckingScope` to make the change clearer.
- Loading branch information
Showing
5 changed files
with
74 additions
and
39 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
third_party/move/move-compiler-v2/tests/checking/abilities/bug_14490_field_abilities.exp
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,9 @@ | ||
|
||
Diagnostics: | ||
error: type `S<T>` is missing required ability `drop` | ||
┌─ tests/checking/abilities/bug_14490_field_abilities.move:7:16 | ||
│ | ||
7 │ entry: S<T>, | ||
│ ^^^^ | ||
│ | ||
= required by declaration of field `entry` |
9 changes: 9 additions & 0 deletions
9
third_party/move/move-compiler-v2/tests/checking/abilities/bug_14490_field_abilities.move
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,9 @@ | ||
module 0x815::demo { | ||
struct S<T: store> has store { | ||
field: T, | ||
} | ||
|
||
struct E<T: store> has store, drop { | ||
entry: S<T>, | ||
} | ||
} |
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