Skip to content

Commit

Permalink
added trait-like test for implicits
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugobros3 committed Sep 4, 2023
1 parent 3fc6509 commit 545b5e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_test(NAME simple_implicit3 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURC
add_test(NAME simple_implicit4 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/implicit4.art)
add_test(NAME simple_implicit5 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/implicit5.art)
add_test(NAME simple_implicit6 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/implicit6.art)
add_test(NAME simple_implicit7 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/implicit7.art)
add_test(NAME simple_while COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/while.art)
add_test(NAME simple_while_let COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/while_let.art)
add_test(NAME simple_for COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/for.art)
Expand Down
12 changes: 12 additions & 0 deletions test/simple/implicit7.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
struct Zero[T] { value: T }
struct Cmp[T] { cmp: fn(T, T) -> bool }

implicit = Zero[i32] { value = 0 };
implicit = Cmp[i32] { cmp = |x, y| x == y };

fn is_zero[T](value: T, implicit zero: Zero[T], implicit cmp: Cmp[T]) -> bool {
cmp.cmp(value, zero.value)
}

#[export]
fn foo(i: i32) = if (is_zero[i32](i)) { 1 } else { 0 };

0 comments on commit 545b5e3

Please sign in to comment.