Skip to content
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

Derive encode/decode compile error[E0308]: mismatched types #686

Closed
dlamar228 opened this issue Jan 27, 2025 · 6 comments · Fixed by #687
Closed

Derive encode/decode compile error[E0308]: mismatched types #686

dlamar228 opened this issue Jan 27, 2025 · 6 comments · Fixed by #687
Assignees

Comments

@dlamar228
Copy link

Description

Encode and decode macro in parity-scale-codec-derive 3.7.1 fails to compile following type:

#[repr(u32)]
#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode)]
enum DigestItemType {
    Other = 0u32,
    Consensus = 4u32,
    Seal = 5u32,
    PreRuntime = 6u32,
    RuntimeEnvironmentUpdated = 8u32,
}
Logs cargo c Compiling proc-macro2 v1.0.93 Compiling unicode-ident v1.0.15 Compiling equivalent v1.0.1 Compiling hashbrown v0.15.2 Compiling rustversion v1.0.19 Compiling winnow v0.6.24 Compiling toml_datetime v0.6.8 Compiling unicode-xid v0.2.6 Compiling serde v1.0.217 Checking byte-slice-cast v1.2.2 Checking arrayvec v0.7.6 Compiling indexmap v2.7.1 Compiling quote v1.0.38 Compiling parity-scale-codec v3.7.1 Compiling syn v2.0.96 Compiling const_format_proc_macros v0.2.34 Checking const_format v0.2.34 Compiling toml_edit v0.22.22 Compiling proc-macro-crate v3.2.0 Compiling impl-trait-for-tuples v0.2.3 Compiling parity-scale-codec-derive v3.7.1 Checking test-sub v0.1.0 (/media/ubuntu/porn30/asd/kuber-atleta/test-sub) error[E0308]: mismatched types --> src/main.rs:8:13 | 8 | Other = 0u32, | ^^^^ expected `usize`, found `u32` | help: change the type of the numeric literal from `u32` to `usize` | 8 | Other = 0usize, | ~~~~~

error[E0308]: mismatched types
--> src/main.rs:9:17
|
9 | Consensus = 4u32,
| ^^^^ expected usize, found u32
|
help: change the type of the numeric literal from u32 to usize
|
9 | Consensus = 4usize,
| ~~~~~

error[E0308]: mismatched types
--> src/main.rs:10:12
|
10 | Seal = 5u32,
| ^^^^ expected usize, found u32
|
help: change the type of the numeric literal from u32 to usize
|
10 | Seal = 5usize,
| ~~~~~

error[E0308]: mismatched types
--> src/main.rs:11:18
|
11 | PreRuntime = 6u32,
| ^^^^ expected usize, found u32
|
help: change the type of the numeric literal from u32 to usize
|
11 | PreRuntime = 6usize,
| ~~~~~

error[E0308]: mismatched types
--> src/main.rs:12:33
|
12 | RuntimeEnvironmentUpdated = 8u32,
| ^^^^ expected usize, found u32
|
help: change the type of the numeric literal from u32 to usize
|
12 | RuntimeEnvironmentUpdated = 8usize,
| ~~~~~

For more information about this error, try rustc --explain E0308.
error: could not compile test-sub (bin "test-sub") due to 10 previous errors

Working version

parity-scale-codec = { version = "=3.6.12", features = ["derive"] }
parity-scale-codec-derive = "=3.6.12"
@serban300
Copy link
Contributor

Seems caused by this PR: #653 . Investigating why.

@pkhry
Copy link
Contributor

pkhry commented Jan 27, 2025

It's because of the consteval check on the literals, thr code expects usize, but got u32 instead. Ie we need to do a check for syn::LitNum for thr suffix and assign type accordingly, otherwise use usize

@jsdw
Copy link
Contributor

jsdw commented Jan 27, 2025

I believe I have a solution for this; will open a quick PR to check.

I'd suggest yanking this release now (if not done already) and doing a new one with the fix merged.

@serban300
Copy link
Contributor

Ok, thank you ! Will yank this release.

@jsdw
Copy link
Contributor

jsdw commented Jan 27, 2025

I hope this PR will fix it: #687

@serban300
Copy link
Contributor

@dlamar228 thank you for the report ! The fix was merged and we published release 3.7.2 . Please let us know if any other issue arises

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants