-
-
Save enigma/e3d689128df7be61f45f493ff545c72d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Take 1 | |
primitive Foo | |
primitive Bar | |
primitive Zoo | |
type Triple is (Foo | Bar | Zoo) | |
class iso _Test is UnitTest | |
fun name():String => "a test" | |
fun apply(h: TestHelper) => | |
let t: Triple = Foo | |
h.assert_eq[Triple](t, Foo) | |
// Fails with: | |
Error: | |
test.pony:60:6: type argument is outside its constraint | |
h.assert_eq[Triple](t, Foo) | |
^ | |
Info: | |
test.pony:53:17: argument: (Foo val | Bar val | Zoo val) | |
type Triple is (Foo | Bar | Zoo) | |
^ | |
.../ponyc/packages/ponytest/helper.pony:119:17: constraint: (Equatable[(Foo val | Bar val | Zoo val)] #read (bind) & Stringable[FormatDefault val, PrefixDefault val] #read (bind)) | |
fun assert_eq[A: (Equatable[A] #read & Stringable #read)] | |
^ | |
// Oh I see, it needs to be Equatable & Stringable: | |
primitive Foo is Equatable[Triple] | |
fun string(fmt: FormatSettings): String iso^ => "Foo".string(fmt) | |
primitive Bar is Equatable[Triple] | |
fun string(fmt: FormatSettings): String iso^ => "Bar".string(fmt) | |
primitive Zoo is Equatable[Triple] | |
fun string(fmt: FormatSettings): String iso^ => "Zoo".string(fmt) | |
// This now works, but I don't really need Zoo so I modify this with: | |
primitive Foo is Equatable[Triple] | |
fun string(fmt: FormatSettings): String iso^ => "Foo".string(fmt) | |
primitive Bar is Equatable[Triple] | |
fun string(fmt: FormatSettings): String iso^ => "Bar".string(fmt) | |
type Triple is (Foo | Bar | None) | |
class iso _Test is UnitTest | |
fun name():String => "a test" | |
fun apply(h: TestHelper) => | |
let t: Triple = Foo | |
h.assert_eq[Triple](t, Foo) | |
// and this fails with: | |
Error: | |
test.pony:49:27: type argument is outside its constraint | |
primitive Foo is Equatable[Triple] | |
^ | |
Info: | |
test.pony:54:17: argument: (Foo val | Bar val | None val) | |
type Triple is (Foo | Bar | None) | |
^ | |
.../ponyc/packages/builtin/comparable.pony:22:21: constraint: Equatable[(Foo val | Bar val | None val)] #read (bind) | |
interface Equatable[A: Equatable[A] #read] | |
^ | |
Error: | |
test.pony:51:27: type argument is outside its constraint | |
primitive Bar is Equatable[Triple] | |
^ | |
Info: | |
test.pony:54:17: argument: (Foo val | Bar val | None val) | |
type Triple is (Foo | Bar | None) | |
^ | |
.../ponyc/packages/builtin/comparable.pony:22:21: constraint: Equatable[(Foo val | Bar val | None val)] #read (bind) | |
interface Equatable[A: Equatable[A] #read] | |
^ | |
Error: | |
test.pony:61:6: type argument is outside its constraint | |
h.assert_eq[Triple](t, Foo) | |
^ | |
Info: | |
test.pony:54:17: argument: (Foo val | Bar val | None val) | |
type Triple is (Foo | Bar | None) | |
^ | |
.../ponyc/packages/ponytest/helper.pony:119:17: constraint: (Equatable[(Foo val | Bar val | None val)] #read (bind) & Stringable[FormatDefault val, PrefixDefault val] #read (bind)) | |
fun assert_eq[A: (Equatable[A] #read & Stringable #read)] | |
// And that is because None is not Equatable[Triple] I'd guess. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment