-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test for simple generic struct type with polymorphic type const…
…raints
- Loading branch information
1 parent
943ec77
commit c0d0d4f
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters