
* Allow compile-time constants as toplevel declarations * Remove the test that fails on toplevel consts * Warn when shadowing a constant * Allow records to be used as compile time constants * Allow data constructors in compile-time constants * Disable some warnings for toplevel constants Since variables and functions cannot be used in the definition of a compile time constants, the following warnings are not going to be reported: * Used/Unused variable * Used/Unused function * Do not reverse constants declarations * Add tests for all valid expressions * Add test for accessing const from namespace * Revert "Do not reverse constants declarations" This reverts commit c4647fadacd134866e4be9c2ab4b0d54870a35fd. * Add test for assigining constant to a constant * Show empty map or record error when assigning to const * Report all invalid constant expressions before fail * Allow accessing records fields in toplevel consts * Undo a mistake * Add test for warning on const shadowing * Show error message when using pattern matching for consts * Remove unused error * Ban toplevel constants in contract interfaces * Varibles rename * Change the error message for invalid_const_id * Make constants public in namespaces and private in contracts * Add a warning about unused constants in contracts * Use ban_when_const for function applications * Test for qualified access of constants in functions * Add failing tests * Add test for the unused const warning * Update CHANGELOG * Update all_syntax test file * Treat expr and type inside bound as bound * Allow typed ids to be used for constants * List valid exprs in the error message for invalid exprs * Fix tests * Update the docs about constants * Update syntax docs * Check validity of const exprs in a separate functions * Call both resolve_const and resolve_fun from resolve_var
89 lines
1.9 KiB
Plaintext
89 lines
1.9 KiB
Plaintext
// Used include
|
|
include "Pair.aes"
|
|
// Unused include
|
|
include "Triple.aes"
|
|
|
|
namespace UnusedNamespace =
|
|
function f() = 1 + g()
|
|
|
|
// Used in f
|
|
private function g() = 2
|
|
|
|
// Unused
|
|
private function h() = 3
|
|
|
|
main contract Warnings =
|
|
|
|
type state = int
|
|
|
|
type unused_type = bool
|
|
|
|
entrypoint init(p) = Pair.fst(p) + Pair.snd(p)
|
|
|
|
stateful entrypoint negative_spend(to : address) = Chain.spend(to, -1)
|
|
|
|
entrypoint shadowing() =
|
|
let x = 1
|
|
let x = 2
|
|
x
|
|
|
|
entrypoint division_by_zero(x) = x / 0
|
|
|
|
stateful entrypoint unused_stateful() = 1
|
|
stateful entrypoint used_stateful(x : int) = put(x)
|
|
|
|
entrypoint unused_variables(unused_arg : int) =
|
|
let unused_var = 10
|
|
let z = 20
|
|
z
|
|
|
|
// Unused functions
|
|
function unused_function() = ()
|
|
function recursive_unused_function() = recursive_unused_function()
|
|
function called_unused_function1() = called_unused_function2()
|
|
function called_unused_function2() = called_unused_function1()
|
|
|
|
function rv() = 1
|
|
entrypoint unused_return_value() =
|
|
rv()
|
|
2
|
|
|
|
namespace FunctionsAsArgs =
|
|
function f() = g()
|
|
|
|
private function g() = h(inc)
|
|
private function h(fn : (int => int)) = fn(1)
|
|
|
|
// Passed as arg to h in g
|
|
private function inc(n : int) : int = n + 1
|
|
// Never used
|
|
private function dec(n : int) : int = n - 1
|
|
|
|
contract Remote =
|
|
entrypoint id(_) = 0
|
|
|
|
contract C =
|
|
payable stateful entrypoint
|
|
call_missing_con() : int = (ct_1111111111111111111111111111112JF6Dz72 : Remote).id(value = 1, 0)
|
|
|
|
namespace ShadowingConst =
|
|
let const = 1
|
|
|
|
function f() =
|
|
let const = 2
|
|
const
|
|
|
|
namespace UnusedConstNamespace =
|
|
// No warnings should be shown even though const is not used
|
|
let const = 1
|
|
|
|
contract UnusedConstContract =
|
|
// Only `c` should show a warning because it is never used in the contract
|
|
let a = 1
|
|
let b = 2
|
|
let c = 3
|
|
|
|
entrypoint f() =
|
|
// Both normal access and qualified access should prevent the unused const warning
|
|
a + UnusedConstContract.b
|