Skip to content

Commit 7345b79

Browse files
committed
fix-12116
1 parent d20ac3d commit 7345b79

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

third_party/move/move-compiler-v2/src/bytecode_generator.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'env> Generator<'env> {
229229
self.error(
230230
id,
231231
format!("cannot assign tuple type `{}` to single variable (use `(a, b, ..) = ..` instead)",
232-
ty.display(&self.env().get_type_display_ctx()))
232+
ty.display(&self.func_env.get_type_display_ctx()))
233233
)
234234
}
235235
self.new_temp(ty)
@@ -379,7 +379,7 @@ impl<'env> Generator<'env> {
379379
format!(
380380
"expected `&mut` but found `{}`",
381381
self.temp_type(lhs_temp)
382-
.display(&self.env().get_type_display_ctx()),
382+
.display(&self.func_env.get_type_display_ctx()),
383383
),
384384
);
385385
}
@@ -588,12 +588,12 @@ impl<'env> Generator<'env> {
588588
{
589589
let err_loc = self.env().get_node_loc(id);
590590
let mut reasons: Vec<(Loc, String)> = Vec::new();
591-
let reason_msg = format!("Invalid call to {}.", op.display(self.env(), id));
591+
let reason_msg = format!("Invalid call to {}.", op.display_with_fun_env(self.env(), &self.func_env, id));
592592
reasons.push((err_loc.clone(), reason_msg.clone()));
593593
let err_msg = format!(
594594
"Expected a struct type. Global storage operations are restricted to struct types declared in the current module. \
595595
Found: '{}'",
596-
self.env().get_node_instantiation(id)[0].display(&self.env().get_type_display_ctx())
596+
self.env().get_node_instantiation(id)[0].display(&self.func_env.get_type_display_ctx())
597597
);
598598
self.env()
599599
.diag_with_labels(Severity::Error, &err_loc, &err_msg, reasons)
@@ -1067,7 +1067,7 @@ impl<'env> Generator<'env> {
10671067
format!(
10681068
"expected `&mut` but found `{}`",
10691069
self.temp_type(oper_temp)
1070-
.display(&self.env().get_type_display_ctx())
1070+
.display(&self.func_env.get_type_display_ctx())
10711071
),
10721072
)
10731073
}

third_party/move/move-compiler-v2/tests/bytecode-generator/v1-typing/global_invalid.exp

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@ module 0x42::m {
1717

1818

1919
Diagnostics:
20-
error: Expected a struct type. Global storage operations are restricted to struct types declared in the current module. Found: '#0'
20+
error: Expected a struct type. Global storage operations are restricted to struct types declared in the current module. Found: 'T'
2121
┌─ tests/bytecode-generator/v1-typing/global_invalid.move:4:17
2222
2323
4 │ assert!(exists<T>(addr), 0);
2424
│ ^^^^^^^^^^^^^^^
2525
│ │
26-
│ Invalid call to exists<#0>.
26+
│ Invalid call to exists<T>.
2727

28-
error: Expected a struct type. Global storage operations are restricted to struct types declared in the current module. Found: '#0'
28+
error: Expected a struct type. Global storage operations are restricted to struct types declared in the current module. Found: 'T'
2929
┌─ tests/bytecode-generator/v1-typing/global_invalid.move:5:17
3030
3131
5 │ let _ = borrow_global<T>(addr);
3232
│ ^^^^^^^^^^^^^^^^^^^^^^
3333
│ │
34-
│ Invalid call to BorrowGlobal(Immutable)<#0>.
34+
│ Invalid call to BorrowGlobal(Immutable)<T>.
3535

36-
error: Expected a struct type. Global storage operations are restricted to struct types declared in the current module. Found: '#0'
36+
error: Expected a struct type. Global storage operations are restricted to struct types declared in the current module. Found: 'T'
3737
┌─ tests/bytecode-generator/v1-typing/global_invalid.move:6:9
3838
3939
6 │ move_from<T>(addr);
4040
│ ^^^^^^^^^^^^^^^^^^
4141
│ │
42-
│ Invalid call to MoveFrom<#0>.
42+
│ Invalid call to MoveFrom<T>.

third_party/move/move-model/src/ast.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -2076,16 +2076,26 @@ impl<'a> ExpDisplay<'a> {
20762076
}
20772077

20782078
impl Operation {
2079-
/// Creates a display of an operation which can be used in formatting.
2080-
pub fn display<'a>(&'a self, env: &'a GlobalEnv, node_id: NodeId) -> OperationDisplay<'a> {
2079+
2080+
fn display_with_context<'a>(&'a self, env: &'a GlobalEnv, node_id: NodeId, tctx: TypeDisplayContext<'a>) -> OperationDisplay<'a> {
20812081
OperationDisplay {
20822082
env,
20832083
oper: self,
20842084
node_id,
2085-
tctx: TypeDisplayContext::new(env),
2085+
tctx,
20862086
}
20872087
}
20882088

2089+
/// Creates a display of an operation which can be used in formatting.
2090+
pub fn display<'a>(&'a self, env: &'a GlobalEnv, node_id: NodeId) -> OperationDisplay<'a> {
2091+
self.display_with_context(env, node_id, env.get_type_display_ctx())
2092+
}
2093+
2094+
/// Creates a display of an operation using the type display ctx from the function.
2095+
pub fn display_with_fun_env<'a>(&'a self, env: &'a GlobalEnv, fun_env : &'a FunctionEnv, node_id: NodeId) -> OperationDisplay<'a> {
2096+
self.display_with_context(env, node_id, fun_env.get_type_display_ctx())
2097+
}
2098+
20892099
fn display_for_exp<'a>(
20902100
&'a self,
20912101
exp_display: &'a ExpDisplay,

0 commit comments

Comments
 (0)