Skip to content

Commit fa97b8b

Browse files
committed
fix had_erros
1 parent a503136 commit fa97b8b

10 files changed

+145
-160
lines changed

third_party/move/move-compiler-v2/tests/checking/typing/neq_invalid.exp

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ error: unable to infer type: `M::G0<?4>`
4242
26 │ G0{} != G0{};
4343
│ ^^^^
4444

45+
error: unable to infer type: `M::G1<?10>`
46+
┌─ tests/checking/typing/neq_invalid.move:27:9
47+
48+
27 │ G1{} != G1{};
49+
│ ^^^^
50+
51+
error: unable to infer type: `M::G2<?16>`
52+
┌─ tests/checking/typing/neq_invalid.move:28:9
53+
54+
28 │ G2{} != G2{};
55+
│ ^^^^
56+
4557
error: invalid call of `!=`: tuples have different arity (3 != 2) for argument 2
4658
┌─ tests/checking/typing/neq_invalid.move:34:22
4759

third_party/move/move-compiler-v2/tests/checking/typing/pack_multiple.exp

+12
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@ error: invalid type instantiation `(u64, u64)`: only structs, vectors, and primi
55
66
5 │ Box { f: (0, 1) };
77
│ ^^^^^^^^^^^^^^^^^
8+
9+
error: invalid type instantiation `(u64, u64, u64)`: only structs, vectors, and primitive types allowed
10+
┌─ tests/checking/typing/pack_multiple.move:6:9
11+
12+
6 │ Box { f: (0, 1, 2) };
13+
│ ^^^^^^^^^^^^^^^^^^^^
14+
15+
error: invalid type instantiation `(bool, M::Box<u64>)`: only structs, vectors, and primitive types allowed
16+
┌─ tests/checking/typing/pack_multiple.move:7:9
17+
18+
7 │ Box { f: (true, Box { f: 0 }) };
19+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

third_party/move/move-compiler-v2/tests/checking/typing/pack_reference.exp

+6
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ error: invalid type instantiation `&u64`: only structs, vectors, and primitive t
55
66
5 │ Box { f: r_imm };
77
│ ^^^^^^^^^^^^^^^^
8+
9+
error: invalid type instantiation `&mut u64`: only structs, vectors, and primitive types allowed
10+
┌─ tests/checking/typing/pack_reference.move:6:9
11+
12+
6 │ Box { f: r_mut };
13+
│ ^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,49 @@
11

22
Diagnostics:
3+
error: invalid type instantiation `&u64`: only structs, vectors, and primitive types allowed
4+
┌─ tests/checking/typing/vector_with_non_base_type.move:4:13
5+
6+
4 │ let v = vector<&u64>[];
7+
│ ^
8+
39
error: invalid type instantiation `&u64`: only structs, vectors, and primitive types allowed
410
┌─ tests/checking/typing/vector_with_non_base_type.move:4:17
511
612
4 │ let v = vector<&u64>[];
713
│ ^^^^^^
14+
15+
error: invalid type instantiation `&mut u64`: only structs, vectors, and primitive types allowed
16+
┌─ tests/checking/typing/vector_with_non_base_type.move:5:13
17+
18+
5 │ let v = vector<&mut u64>[];
19+
│ ^
20+
21+
error: invalid type instantiation `&mut u64`: only structs, vectors, and primitive types allowed
22+
┌─ tests/checking/typing/vector_with_non_base_type.move:5:17
23+
24+
5 │ let v = vector<&mut u64>[];
25+
│ ^^^^^^
26+
27+
error: invalid type instantiation `()`: only structs, vectors, and primitive types allowed
28+
┌─ tests/checking/typing/vector_with_non_base_type.move:6:13
29+
30+
6 │ let v = vector<()>[];
31+
│ ^
32+
33+
error: invalid type instantiation `()`: only structs, vectors, and primitive types allowed
34+
┌─ tests/checking/typing/vector_with_non_base_type.move:6:17
35+
36+
6 │ let v = vector<()>[];
37+
│ ^^^^^^
38+
39+
error: invalid type instantiation `(u64, bool)`: only structs, vectors, and primitive types allowed
40+
┌─ tests/checking/typing/vector_with_non_base_type.move:7:13
41+
42+
7 │ let v = vector<(u64, bool)>[];
43+
│ ^
44+
45+
error: invalid type instantiation `(u64, bool)`: only structs, vectors, and primitive types allowed
46+
┌─ tests/checking/typing/vector_with_non_base_type.move:7:17
47+
48+
7 │ let v = vector<(u64, bool)>[];
49+
│ ^^^^^^

third_party/move/move-compiler-v2/tests/checking/typing/vector_with_non_base_type_2.exp

-25
This file was deleted.

third_party/move/move-compiler-v2/tests/checking/typing/vector_with_non_base_type_2.move

-22
This file was deleted.

third_party/move/move-compiler-v2/tests/checking/typing/vector_with_non_base_type_inferred.exp

+30
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,33 @@ error: invalid type instantiation `&u64`: only structs, vectors, and primitive t
55
66
4 │ vector[&0];
77
│ ^^^^^^
8+
9+
error: invalid type instantiation `&mut u64`: only structs, vectors, and primitive types allowed
10+
┌─ tests/checking/typing/vector_with_non_base_type_inferred.move:5:9
11+
12+
5 │ vector[&mut 0];
13+
│ ^^^^^^
14+
15+
error: invalid type instantiation `()`: only structs, vectors, and primitive types allowed
16+
┌─ tests/checking/typing/vector_with_non_base_type_inferred.move:6:9
17+
18+
6 │ vector[()];
19+
│ ^^^^^^
20+
21+
error: invalid type instantiation `(u64, bool)`: only structs, vectors, and primitive types allowed
22+
┌─ tests/checking/typing/vector_with_non_base_type_inferred.move:7:9
23+
24+
7 │ vector[(0, false)];
25+
│ ^^^^^^
26+
27+
error: invalid type instantiation `&u64`: only structs, vectors, and primitive types allowed
28+
┌─ tests/checking/typing/vector_with_non_base_type_inferred.move:9:9
29+
30+
9 │ vector[&0, &mut 0];
31+
│ ^^^^^^
32+
33+
error: invalid type instantiation `&u64`: only structs, vectors, and primitive types allowed
34+
┌─ tests/checking/typing/vector_with_non_base_type_inferred.move:10:9
35+
36+
10 │ vector[&mut 0, &0];
37+
│ ^^^^^^

third_party/move/move-compiler-v2/tests/checking/typing/vector_with_non_base_type_inferred_2.exp

-37
This file was deleted.

third_party/move/move-compiler-v2/tests/checking/typing/vector_with_non_base_type_inferred_2.move

-32
This file was deleted.

third_party/move/move-model/src/builder/exp_builder.rs

+43-44
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,21 @@ impl<'env, 'translator, 'module_translator> ExpTranslator<'env, 'translator, 'mo
348348
/// Finalizes types in this translator, producing errors if some could not be inferred
349349
/// and remained incomplete.
350350
pub fn finalize_types(&mut self) {
351-
for i in self.node_counter_start..self.parent.parent.env.next_free_node_number() {
352-
let node_id = NodeId::new(i);
351+
if !self.had_errors {
352+
for i in self.node_counter_start..self.parent.parent.env.next_free_node_number() {
353+
let node_id = NodeId::new(i);
353354

354-
if let Some(ty) = self.get_node_type_opt(node_id) {
355-
let ty = self.finalize_type(node_id, &ty);
356-
self.update_node_type(node_id, ty);
357-
}
358-
if let Some(inst) = self.get_node_instantiation_opt(node_id) {
359-
let inst = inst
360-
.iter()
361-
.map(|ty| self.finalize_type(node_id, ty))
362-
.collect_vec();
363-
self.update_node_instantiation(node_id, inst);
355+
if let Some(ty) = self.get_node_type_opt(node_id) {
356+
let ty = self.finalize_type(node_id, &ty);
357+
self.update_node_type(node_id, ty);
358+
}
359+
if let Some(inst) = self.get_node_instantiation_opt(node_id) {
360+
let inst = inst
361+
.iter()
362+
.map(|ty| self.finalize_type(node_id, ty))
363+
.collect_vec();
364+
self.update_node_instantiation(node_id, inst);
365+
}
364366
}
365367
}
366368
}
@@ -369,39 +371,36 @@ impl<'env, 'translator, 'module_translator> ExpTranslator<'env, 'translator, 'mo
369371
/// invalid type instantiations are found.
370372
fn finalize_type(&mut self, node_id: NodeId, ty: &Type) -> Type {
371373
let ty = self.subs.specialize_with_defaults(ty);
372-
// Report error only if there are no other errors in this builder,
373-
// to avoid noisy followup errors.
374-
if !self.had_errors {
375-
let loc = self.parent.parent.env.get_node_loc(node_id);
376-
let mut incomplete = false;
377-
let mut visitor = |t: &Type| {
378-
use Type::*;
379-
match t {
380-
Var(_) => {
381-
incomplete = true;
382-
},
383-
Struct(_, _, inst) => {
384-
for i in inst {
385-
self.check_valid_instantiation(&loc, i)
386-
}
387-
},
388-
Vector(t) => self.check_valid_instantiation(&loc, t),
389-
_ => {},
390-
}
391-
};
392-
ty.visit(&mut visitor);
393-
394-
if incomplete {
395-
// This type could not be fully inferred.
396-
self.error(
397-
&loc,
398-
&format!(
399-
"unable to infer type: `{}`",
400-
ty.display(&self.type_display_context())
401-
),
402-
);
374+
let loc = self.parent.parent.env.get_node_loc(node_id);
375+
let mut visitor = |t: &Type| {
376+
use Type::*;
377+
match t {
378+
Var(_) => {
379+
self.error(
380+
&loc,
381+
&format!(
382+
"unable to infer type: `{}`",
383+
ty.display(&self.type_display_context())
384+
),
385+
);
386+
let _ = self.subs.unify(
387+
&self.unification_context,
388+
self.type_variance(),
389+
WideningOrder::RightToLeft,
390+
t,
391+
&Error,
392+
);
393+
},
394+
Struct(_, _, inst) => {
395+
for i in inst {
396+
self.check_valid_instantiation(&loc, i)
397+
}
398+
},
399+
Vector(t) => self.check_valid_instantiation(&loc, t),
400+
_ => {},
403401
}
404-
}
402+
};
403+
ty.visit(&mut visitor);
405404
ty
406405
}
407406

0 commit comments

Comments
 (0)