mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-22 22:44:47 +03:00
Fix and add test
This commit is contained in:
parent
c4ceeb0369
commit
781d7a816a
@ -70,7 +70,7 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
|
||||
|
||||
// Lookup the variable in the symbol table and retrieve its type.
|
||||
let var_type = if let Some(var) =
|
||||
self.symbol_table.borrow_mut().lookup_variable(Location::new(None, var_name.name))
|
||||
self.symbol_table.borrow().lookup_variable(Location::new(None, var_name.name))
|
||||
{
|
||||
// If the variable exists, then check that it is not a constant.
|
||||
match &var.declaration {
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [ETYC0372097]: Cannot re-assign to `try_get_token` in an outer scope in a finalize block.\n --> compiler-test:16:13\n |\n 16 | let try_get_token: TokenInfo = Mapping::get_or_use(\n | ^^^^^^^^^^^^^\n |\n = This is a fundamental restriction that can often be avoided by using a ternary operator `?` or re-declaring the variable in the current scope. In the future, ARC XXXX (https://github.com/AleoHQ/ARCs) will support more complex assignments in finalize blocks.\n"
|
@ -3,16 +3,16 @@ namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- - compile:
|
||||
- initial_symbol_table: 9bd9265feccd95ed896c73c966728add44d1683a9af934f028653148d0a1974f
|
||||
type_checked_symbol_table: d0c2f7a1c92c7f3f5082a13126fe299ebdbc6230d3ba5fe2aef98521ca7980c1
|
||||
unrolled_symbol_table: d0c2f7a1c92c7f3f5082a13126fe299ebdbc6230d3ba5fe2aef98521ca7980c1
|
||||
initial_ast: 42fe71a0071c69c50a20580b772790a5c59ae03f86667f808221a031b444d3e4
|
||||
unrolled_ast: 42fe71a0071c69c50a20580b772790a5c59ae03f86667f808221a031b444d3e4
|
||||
ssa_ast: ea973cac72553e3038ae1cc8c82bfa08f4d573374704fb9ab0b7818de47bbfad
|
||||
flattened_ast: 527bf92474e805a34f0b5c944296e55c2d0e2e37d6ca42bc0cdfa0933ea314d9
|
||||
destructured_ast: e49e7cbbc94a66e6094bd63d8fbb2d998d81c3fc2d726d05b8bfc5b08216857d
|
||||
inlined_ast: e49e7cbbc94a66e6094bd63d8fbb2d998d81c3fc2d726d05b8bfc5b08216857d
|
||||
dce_ast: e49e7cbbc94a66e6094bd63d8fbb2d998d81c3fc2d726d05b8bfc5b08216857d
|
||||
bytecode: d1cb76177aa7ffcdc033855e2696b25791292c7c6b38fdc3c1e145dadc0f838a
|
||||
- initial_symbol_table: 21825a8dac4deb40f1fad189f80a10b09476933d40dd0a49858a0ecca09b78cd
|
||||
type_checked_symbol_table: d505f9428b437cf2a53c428045d479ead9c6d24207e5f6091fb7fb605371d4a1
|
||||
unrolled_symbol_table: d505f9428b437cf2a53c428045d479ead9c6d24207e5f6091fb7fb605371d4a1
|
||||
initial_ast: 43e963abf094772989fcd155f5ccbfb6ebb7733b6c2771204618ed21b65e610f
|
||||
unrolled_ast: 43e963abf094772989fcd155f5ccbfb6ebb7733b6c2771204618ed21b65e610f
|
||||
ssa_ast: 4a369465cbc0721e726b33e59675eeea9a8c9e3322b147dac0bded10e5f7e444
|
||||
flattened_ast: be20fcccb2c9fb0e377f5af555a0b91fe37c77a8891da404eeaff646b286a199
|
||||
destructured_ast: 5bd0856b06230dc1ced541f0014a73026fb5bc39446a50d0f599d82e740580ae
|
||||
inlined_ast: 5bd0856b06230dc1ced541f0014a73026fb5bc39446a50d0f599d82e740580ae
|
||||
dce_ast: 5bd0856b06230dc1ced541f0014a73026fb5bc39446a50d0f599d82e740580ae
|
||||
bytecode: 794ba5825cf2e90cf1ee0486d7b4614f0477a5ca590c2eea6c2c172142e44790
|
||||
errors: ""
|
||||
warnings: ""
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
configs:
|
||||
- dce_enabled : false
|
||||
*/
|
||||
|
||||
program test.aleo {
|
||||
struct TokenInfo {
|
||||
id: u64,
|
||||
}
|
||||
mapping token_name_to_info: field => TokenInfo;
|
||||
|
||||
|
||||
transition add_new_liquidity_token_2 () {
|
||||
return then finalize();
|
||||
}
|
||||
|
||||
|
||||
finalize add_new_liquidity_token_2() {
|
||||
let try_get_token: TokenInfo = Mapping::get_or_use(
|
||||
token_name_to_info,
|
||||
0field,
|
||||
TokenInfo { id: 0u64 }
|
||||
);
|
||||
if try_get_token.id == 0u64 {
|
||||
try_get_token = TokenInfo { id: 10u64 };
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,24 +32,6 @@ program test.aleo {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
transition add_new_liquidity_token_2 () {
|
||||
return then finalize();
|
||||
}
|
||||
|
||||
|
||||
finalize add_new_liquidity_token_2() {
|
||||
let try_get_token: TokenInfo = Mapping::get_or_use(
|
||||
token_name_to_info,
|
||||
0field,
|
||||
TokenInfo { id: 0u64 }
|
||||
);
|
||||
if try_get_token.id == 0u64 {
|
||||
try_get_token = TokenInfo { id: 10u64 };
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user