Generics.k 589 B

12345678910111213141516171819202122232425
  1. invoke {
  2. interface Box<T> {
  3. unwrap () -> T
  4. }
  5. class SimpleBox<T> is Box<T> {
  6. init (x: T) {
  7. do nothing
  8. }
  9. unwrap () -> T {
  10. return x
  11. }
  12. }
  13. assert SimpleBox<Int> ~~ SimpleBox<Int>
  14. assert SimpleBox<Int> is TypeType<SimpleBox>
  15. assert SimpleBox<Int> is Impl<Box<Int>>
  16. let b = SimpleBox<String>('b')
  17. assert b is SimpleBox
  18. assert b is SimpleBox<String>
  19. assert b is not SimpleBox<Int>
  20. assert b is Box
  21. assert b is Box<String>
  22. assert b is not Box<Int>
  23. assert b->unwrap() == 'b'
  24. }