-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Labels
Description
🐛 Bug
Calling a function like (f)()
when an argument is a match with >=11 arms cannot be compiled.
To reproduce
Code snippet to reproduce
//# publish
module 0xCAFE::Module0 {
enum Enum0 has copy, drop {
Variant1,
Variant2,
Variant3,
Variant4,
Variant5,
Variant6,
Variant7,
Variant8,
Variant9,
Variant10,
Variant11,
}
public fun function1(_x: &u8) {}
public fun function2() {
(function1)(
match (Enum0::Variant1) {
Enum0::Variant1 => &1,
Enum0::Variant2 => &1,
Enum0::Variant3 => &1,
Enum0::Variant4 => &1,
Enum0::Variant5 => &1,
Enum0::Variant6 => &1,
Enum0::Variant7 => &1,
Enum0::Variant8 => &1,
Enum0::Variant9 => &1,
Enum0::Variant10 => &1,
Enum0::Variant11 => &1,
}
);
}
}
Stack trace/error message
task 0 'publish'. lines 1-34:
Error: compilation errors:
error: value of type `|&u8|` does not have the `copy` ability
┌─ TEMPFILE:18:9
│
18 │ ╭ (function1)(
19 │ │ match (Enum0::Variant1) {
20 │ │ Enum0::Variant1 => &1,
21 │ │ Enum0::Variant2 => &1,
· │
31 │ │ }
32 │ │ );
│ ╰─────────^ copy needed here because value is still in use
error: value of type `|&u8|` does not have the `drop` ability
┌─ TEMPFILE:18:9
│
18 │ ╭ (function1)(
19 │ │ match (Enum0::Variant1) {
20 │ │ Enum0::Variant1 => &1,
21 │ │ Enum0::Variant2 => &1,
· │
31 │ │ }
32 │ │ );
│ ╰─────────^ still borrowed but will be implicitly dropped later since it is no longer used
Expected Behavior
It should compile without giving errors.
Additional context
Making any of the following modification will make it compile fine:
- Change
(function1)(...)
tofunction1(...)
- Make the match have fewer than 11 arms
- Remove any variant in Enum0 and the corresponding arm in match
- Use
_ => &1
to replace two or more arms
- Change
_x: &u8
to_x: u8
and all&1
to1
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
For Grabs