-
Notifications
You must be signed in to change notification settings - Fork 100
Disallow duplicated enum variant indices #628
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
Changes from 10 commits
e6b0b0f
c986e06
56c6b3a
722f02e
f2cc6c0
7aa0d89
7b92913
614f2b7
9e3c8a6
df86890
6f31b67
f2255ee
add9eae
77396b9
a25db72
9112b92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ fn scale_codec_ui_tests() { | |
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/scale_codec_ui/*.rs"); | ||
t.pass("tests/scale_codec_ui/pass/*.rs"); | ||
t.compile_fail("tests/scale_codec_ui/fail/*.rs"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not put those tests at "tests/scale_codec_ui/" ? (anyway I don't mind) |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#[derive(::parity_scale_codec::Decode, ::parity_scale_codec::Encode)] | ||
#[codec(crate = ::parity_scale_codec)] | ||
enum T { | ||
A = 3, | ||
#[codec(index = 3)] | ||
B, | ||
} | ||
|
||
#[derive(::parity_scale_codec::Decode, ::parity_scale_codec::Encode)] | ||
#[codec(crate = ::parity_scale_codec)] | ||
enum T1 { | ||
A, | ||
#[codec(index = 0)] | ||
B, | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error: Duplicate variant index. qed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. QED means: quod erat demonstrandum = which was to be demonstrated. I think it doesn't fit in an error message. Maybe writing: scale codec error: Invalid variant index, the variant index is duplicated. |
||
--> tests/scale_codec_ui/fail/codec_duplicate_index.rs:5:2 | ||
| | ||
5 | #[codec(index = 3)] | ||
| ^ | ||
|
||
error: Variant index already defined here. | ||
--> tests/scale_codec_ui/fail/codec_duplicate_index.rs:4:2 | ||
| | ||
4 | A = 3, | ||
| ^ | ||
|
||
error: Duplicate variant index. qed | ||
--> tests/scale_codec_ui/fail/codec_duplicate_index.rs:13:2 | ||
| | ||
13 | #[codec(index = 0)] | ||
| ^ | ||
|
||
error: Variant index already defined here. | ||
--> tests/scale_codec_ui/fail/codec_duplicate_index.rs:12:2 | ||
| | ||
12 | A, | ||
| ^ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#[derive(::parity_scale_codec::Decode, ::parity_scale_codec::Encode)] | ||
#[codec(crate = ::parity_scale_codec)] | ||
enum T { | ||
A = 1, | ||
B, | ||
} | ||
|
||
#[derive(::parity_scale_codec::Decode, ::parity_scale_codec::Encode)] | ||
#[codec(crate = ::parity_scale_codec)] | ||
enum T2 { | ||
#[codec(index = 1)] | ||
A, | ||
B, | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error: Custom variant index is duplicated later. qed | ||
--> tests/scale_codec_ui/fail/discriminant_variant_counted_in_default_index.rs:4:2 | ||
| | ||
4 | A = 1, | ||
| ^ | ||
|
||
error: Variant index derived here. | ||
--> tests/scale_codec_ui/fail/discriminant_variant_counted_in_default_index.rs:5:2 | ||
| | ||
5 | B, | ||
| ^ | ||
|
||
error: Custom variant index is duplicated later. qed | ||
--> tests/scale_codec_ui/fail/discriminant_variant_counted_in_default_index.rs:11:2 | ||
| | ||
11 | #[codec(index = 1)] | ||
| ^ | ||
|
||
error: Variant index derived here. | ||
--> tests/scale_codec_ui/fail/discriminant_variant_counted_in_default_index.rs:13:2 | ||
| | ||
13 | B, | ||
| ^ |
Uh oh!
There was an error while loading. Please reload this page.