mismatched types
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.9k
- Forks
- 231
- Avg merge
- 19h 55m
- Merged PRs (30d)
- 67
Description
#![feature(no_core, lang_items)]
#![no_core]
#[lang = "sized"]
pub trait Sized {}
extern "C" {
fn printf(format: *const i8, ...);
}
enum ast<'a> {
num(usize),
add(&'a ast<'a>, &'a ast<'a>),
}
fn eval(node: &ast) -> usize {
match node {
ast::num(n) => *n,
ast::add(l, r) => eval(l) + eval(r),
}
}
fn main() -> i32 {
let a = ast::num(3);
let b = ast::num(4);
let c = ast::add(&a, &b);
let d = ast::num(10);
let e = ast::add(&c, &d);
unsafe {
printf("%d\n\0" as *const str as *const i8, eval(&e) as i32);
}
0
}
with my recusive adts work this fails with:
test.rs:31:5: error: mismatched types, expected ‘& ast’ but got ‘ast’ [E0308]
31 | match node {
| ^~~~~ ~~~~
32 | ast::num(n) => *n,
| ~~~
test.rs:31:5: error: mismatched types, expected ‘& ast’ but got ‘ast’ [E0308]
31 | match node {
| ^~~~~ ~~~~
32 | ast::num(n) => *n,
33 | ast::add(l, r) => eval(l) + eval(r),
| ~~~
test.rs:40:22: error: mismatched types, expected ‘ast’ but got ‘ast’ [E0308]
27 | add(&'a ast<'a>, &'a ast<'a>),
| ~~~
......
40 | let c = ast::add(&a, &b);
| ^~
test.rs:42:23: error: cannot find value ‘c’ in this scope [E0425]
42 | let e = ast::add(&c, &d);
| ^
test.rs:42:22: error: failed to resolve argument type
42 | let e = ast::add(&c, &d);
| ^
test.rs:44:60: error: cannot find value ‘e’ in this scope [E0425]
44 | printf("%d\n\0" as *const str as *const i8, eval(&e) as i32);
| ^
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied test.rs reproducer first and confirm the recursive ADT mismatched-type errors. Then trace the compiler's recursive ADT and type-checking handling to determine why references are treated as mismatched types; done means the reproducer compiles without these errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100