1
0
forked from Mirror/wren

It turns out "is" is just a normal overridable operator. Who knew?

This commit is contained in:
Bob Nystrom
2015-11-07 13:00:24 -08:00
parent 931d9ca4d3
commit 7ae9888c4f
5 changed files with 30 additions and 4 deletions

View File

@ -1,33 +0,0 @@
System.print(Num is Class) // expect: true
System.print(true is Bool) // expect: true
System.print(Fn.new { 1 } is Fn) // expect: true
System.print(123 is Num) // expect: true
System.print(null is Null) // expect: true
System.print("s" is String) // expect: true
System.print(Num is Bool) // expect: false
System.print(null is Class) // expect: false
System.print(true is Fn) // expect: false
System.print(Fn.new { 1 } is Num) // expect: false
System.print("s" is Null) // expect: false
System.print(123 is String) // expect: false
// Everything extends Object.
System.print(Num is Object) // expect: true
System.print(null is Object) // expect: true
System.print(true is Object) // expect: true
System.print(Fn.new { 1 } is Object) // expect: true
System.print("s" is Object) // expect: true
System.print(123 is Object) // expect: true
// Classes extend Class.
System.print(Num is Class) // expect: true
System.print(null is Class) // expect: false
System.print(true is Class) // expect: false
System.print(Fn.new { 1 } is Class) // expect: false
System.print("s" is Class) // expect: false
System.print(123 is Class) // expect: false
// Ignore newline after "is".
System.print(123 is
Num) // expect: true

View File

@ -1 +0,0 @@
1 is false // expect runtime error: Right operand must be a class.

View File

@ -14,6 +14,7 @@ class Foo {
!=(other) { "infix != " + other }
&(other) { "infix & " + other }
|(other) { "infix | " + other }
is(other) { "infix is " + other }
! { "prefix !" }
~ { "prefix ~" }
@ -37,3 +38,4 @@ System.print(foo | "a") // expect: infix | a
System.print(!foo) // expect: prefix !
System.print(~foo) // expect: prefix ~
System.print(-foo) // expect: prefix -
System.print(foo is "a") // expect: infix is a