diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-03-18 15:18:21 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-03-19 08:44:25 +0000 |
commit | f0750d7091a7f9014d4327cc13f4625af2da2500 (patch) | |
tree | 0022208828fa5c37ddfbaeca23a75f1a8eb28c55 /gcc | |
parent | 196476601e64a954ad10fb0a728038aedae93155 (diff) | |
download | gcc-f0750d7091a7f9014d4327cc13f4625af2da2500.zip gcc-f0750d7091a7f9014d4327cc13f4625af2da2500.tar.gz gcc-f0750d7091a7f9014d4327cc13f4625af2da2500.tar.bz2 |
Fix type unification for Inference Variables and return types
When we resolve the type of an expression such as a LiteralExpr with HIR id
10, but is the final expression in a BlockExpr of HirId 11. The same type
is infered for the entire BlockExpr as well as the final Expr but we
override the reference id on the TyTy::Type. This means if there is a
change in reference id the old ID must be added to the combined reference
chain for type inference to take place.
Fixes #293
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.h | 7 | ||||
-rw-r--r-- | gcc/testsuite/rust.test/compilable/block_expr4.rs | 7 |
2 files changed, 13 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 9fe7417..2d97a0b 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -57,7 +57,12 @@ public: HirId get_ref () const { return ref; } - void set_ref (HirId id) { ref = id; } + void set_ref (HirId id) + { + if (id != ref) + append_reference (ref); + ref = id; + } HirId get_ty_ref () const { return ty_ref; } diff --git a/gcc/testsuite/rust.test/compilable/block_expr4.rs b/gcc/testsuite/rust.test/compilable/block_expr4.rs new file mode 100644 index 0000000..35a5cd0 --- /dev/null +++ b/gcc/testsuite/rust.test/compilable/block_expr4.rs @@ -0,0 +1,7 @@ +fn foo() -> isize { + 0 +} + +fn main() { + let a = foo(); +} |