-
Notifications
You must be signed in to change notification settings - Fork 590
/
Copy pathtrait_default_fn
109 lines (81 loc) · 1.97 KB
/
trait_default_fn
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! > Test default implementation with basic implementation and override.
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: false)
//! > function
fn foo() {
MyTrait::foo(5_u64);
MyTrait::foo(3_u32);
}
//! > function_name
foo
//! > module_code
trait MyTrait<T> {
fn foo(t: T) -> T {
t
}
}
impl MyImplU64 of MyTrait<u64>;
impl MyImplU32 of MyTrait<u32> {
fn foo(t: u32) -> u32 {
t + 1
}
}
//! > expected_diagnostics
//! > ==========================================================================
//! > Test default implementation with a self reference.
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: false)
//! > function
fn foo() {}
//! > function_name
foo
//! > module_code
trait MyTrait<T> {
fn inner(x: T, y: T) -> T;
fn foo<+Copy<T>>(x: T) -> T {
Self::inner(x, x)
}
}
impl MyImplU32 of MyTrait<u32> {
fn inner(x: u32, y: u32) -> u32 {
x + y
}
}
//! > expected_diagnostics
//! > ==========================================================================
//! > Test default implementation with mut.
//! > TODO(oziv): Support mut in default implementations.
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function
fn foo() {}
//! > function_name
foo
//! > module_code
trait MyTrait {
fn foo(mut x: u32) -> u32 {
x += 1;
x
}
}
//! > expected_diagnostics
error: Parameter of trait function `MyTrait::foo` can't be defined as mutable.
--> lib.cairo:2:12
fn foo(mut x: u32) -> u32 {
^^^
//! > ==========================================================================
//! > Test default implementation with using `Self` as an outside impl.
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: false)
//! > function
fn foo() {}
//! > function_name
foo
//! > module_code
trait MyTrait {
fn default_impl() {
bar::<Self>();
}
}
fn bar<+MyTrait>() {}
//! > expected_diagnostics