-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtype_check.atlas
63 lines (47 loc) · 1.53 KB
/
type_check.atlas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Type Checking Test Case
// Define constants and variables
// Function definitions
func add(a: i64, b: i64) -> i64 {
return a + b; // Valid addition of i64
}
func negate(a: u64) -> u64 {
// Attempt to negate a u64 - this should fail type checking
return -a; // Invalid: u64 cannot be negated
}
func test_consts() -> i64 {
const a: i64 = 10; // Constant i64
// Attempt to mutate a const - this should fail type checking
a = 15.0; // Invalid: 'a' is a constant
return a;
}
// If-else block with type checking
func conditional_check(a: i64) -> bool {
if a > 10 {
return true;
} else {
return false;
}
}
// While loop with type checking
func sum_until(limit: i64) -> i64 {
let sum: i64 = 0;
let counter: i64 = 0;
while counter < limit {
sum = add(sum, counter); // Valid addition
counter = counter + 1; // Increment counter
}
return sum;
}
func add_i_f(a: i64, b: f64) -> i64 {
return a + b; // Invalid: i64 + f64
}
// Main function for testing
func main() -> i64 {
let valid_sum: i64 = add(10, 20); // Valid function call
let invalid_negate: u64 = negate(5_u64); // This should trigger a type-checking error
let const_mutation: i64 = test_consts(); // This should trigger a type-checking error
let result: bool = conditional_check(15); // Valid conditional check
let total: i64 = sum_until(10); // Valid while loop execution
//let add_i_f: i64 = add_i_f(10, 5.0); // This should trigger a type-checking error
return total;
}