Skip to content

Commit

Permalink
Added test for simple generic struct type with polymorphic type const…
Browse files Browse the repository at this point in the history
…raints
  • Loading branch information
IsaacShelton committed Dec 15, 2024
1 parent 943ec77 commit c0d0d4f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/generics_struct_with_constraints/main.adept
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

pragma => adept("3.0")

#[foreign]
func printf(format ptr<char>, ...) int

struct PrimitiveAdditionPair<$T: PrimitiveAdd> (a $T, b $T)

struct Another<$T: PrimitiveAdd> (a PrimitiveAdditionPair<$T>)

func main {
pair := PrimitiveAdditionPair<int> { a: 8, b: 13 }

printf(c"Hello, world! From generic structs with constraints!\n")
printf(c"The result is: %d\n", pair.compute())

// The following is invalid, because `ptr<char>` does not satisfy `PrimitiveAdd`
/* invalid_pair := PrimitiveAdditionPair<ptr<char>> { a: c"arst", b: c"oien" } */
/* printf(c"The result is: %p\n", invalid_pair.compute()) */
}

func compute(pair PrimitiveAdditionPair<$T: PrimitiveAdd>) $T {
return pair.a + pair.b
}

1 change: 1 addition & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ compile function_parameters
compile function_simple
compile generics
compile generics_struct_simple
compile generics_struct_with_constraints
compile global_variables
compile hello_world
compile if
Expand Down

0 comments on commit c0d0d4f

Please sign in to comment.