feat: newer rules around casting Data
* you cannot cast FROM Data with a `let` * you cannot cast FROM Data by passing Data to none Data when calling a function * you MUST use `assert` to cast from data * you can cast INTO Data with a `let` * you can cast INTO Data by passing none Data to Data when calling a function * You cannot assert cast Data without an annotation
This commit is contained in:
5
examples/acceptance_tests/050/aiken.lock
Normal file
5
examples/acceptance_tests/050/aiken.lock
Normal file
@@ -0,0 +1,5 @@
|
||||
# This file was generated by Aiken
|
||||
# You typically do not need to edit this file
|
||||
|
||||
requirements = []
|
||||
packages = []
|
||||
3
examples/acceptance_tests/050/aiken.toml
Normal file
3
examples/acceptance_tests/050/aiken.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
name = 'aiken-lang/acceptance_test_050'
|
||||
version = '0.0.0'
|
||||
description = ''
|
||||
40
examples/acceptance_tests/050/lib/tests.ak
Normal file
40
examples/acceptance_tests/050/lib/tests.ak
Normal file
@@ -0,0 +1,40 @@
|
||||
use aiken/builtin
|
||||
|
||||
pub type Thing {
|
||||
wow: Int,
|
||||
}
|
||||
|
||||
test assert_1() {
|
||||
assert thing: Thing = builtin.constr_data(0, [builtin.i_data(1)])
|
||||
|
||||
thing.wow == 1
|
||||
}
|
||||
|
||||
fn cast_to_thing(x: Data) -> Thing {
|
||||
assert x: Thing = x
|
||||
|
||||
x
|
||||
}
|
||||
|
||||
test assert_2() {
|
||||
let thing = Thing { wow: 1 }
|
||||
|
||||
let still_thing = cast_to_thing(thing)
|
||||
|
||||
still_thing.wow == 1
|
||||
}
|
||||
// should not typecheck
|
||||
// test unlift_data_without_assert_1() {
|
||||
// let thing: Thing = builtin.constr_data(0, [builtin.i_data(1)])
|
||||
// thing.wow == 1
|
||||
// }
|
||||
|
||||
// should not typecheck
|
||||
// fn bad_cast(x: Thing) -> Int {
|
||||
// x.wow
|
||||
// }
|
||||
|
||||
// test unlift_data_without_assert_2() {
|
||||
// let thing = builtin.constr_data(0, [builtin.i_data(1)])
|
||||
// bad_cast(thing) == 1
|
||||
// }
|
||||
Reference in New Issue
Block a user