-
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.
Merge pull request #151 from kyleect/instanceof
Implement `instanceof` function
- Loading branch information
Showing
20 changed files
with
246 additions
and
4 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
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
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,15 @@ | ||
class Test {} | ||
|
||
let f; | ||
|
||
let value = 100; | ||
|
||
{ | ||
fn add (n) { | ||
return a + value; | ||
} | ||
|
||
f = add; | ||
} | ||
|
||
println(instanceof(f, Test)); // out: TypeError: expected type "instance" but got "function" |
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,7 @@ | ||
class Test { | ||
|
||
} | ||
|
||
let test = Test(); | ||
|
||
println(instanceof(false, Test)); // out: TypeError: expected type "instance" but got "bool" |
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,7 @@ | ||
class Test {} | ||
|
||
fn test () { | ||
|
||
} | ||
|
||
println(instanceof(test, Test)); // out: TypeError: expected type "instance" but got "function" |
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,7 @@ | ||
class Test { | ||
|
||
} | ||
|
||
let test = Test(); | ||
|
||
println(instanceof(test, Test)); // out: true |
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,24 @@ | ||
class GrandParent {} | ||
|
||
class Parent extends GrandParent { | ||
|
||
} | ||
|
||
class Child extends Parent { | ||
|
||
} | ||
|
||
class OtherChild extends Parent { | ||
|
||
} | ||
|
||
class Grandchild extends Child { | ||
|
||
} | ||
|
||
let instance = Grandchild(); | ||
|
||
println(instanceof(instance, Grandchild)); // out: true | ||
println(instanceof(instance, Child)); // out: true | ||
println(instanceof(instance, Parent)); // out: true | ||
println(instanceof(instance, OtherChild)); // out: false |
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,11 @@ | ||
class Test { | ||
|
||
} | ||
|
||
class Wrong { | ||
|
||
} | ||
|
||
let test = Test(); | ||
|
||
println(instanceof(test, Wrong)); // out: false |
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,7 @@ | ||
class Test { | ||
|
||
} | ||
|
||
let test = Test(); | ||
|
||
println(instanceof([], Test)); // out: TypeError: expected type "instance" but got "list" |
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,9 @@ | ||
class Test { | ||
fn test (a, b) { | ||
return a + b; | ||
} | ||
} | ||
|
||
let test = Test(); | ||
|
||
println(instanceof(test.test, Test)); // out: TypeError: expected type "instance" but got "function" |
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,3 @@ | ||
class Test {} | ||
|
||
println(instanceof(clock, Test)); // out: TypeError: expected type "instance" but got "function" |
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,7 @@ | ||
class Test { | ||
|
||
} | ||
|
||
let test = Test(); | ||
|
||
println(instanceof(nil, Test)); // out: TypeError: expected type "instance" but got "nil" |
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,7 @@ | ||
class Test { | ||
|
||
} | ||
|
||
let test = Test(); | ||
|
||
println(instanceof(123, Test)); // out: TypeError: expected type "instance" but got "number" |
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,7 @@ | ||
class Test { | ||
|
||
} | ||
|
||
let test = Test(); | ||
|
||
println(instanceof("test", Test)); // out: TypeError: expected type "instance" but got "string" |
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,7 @@ | ||
class Test { | ||
|
||
} | ||
|
||
let test = Test(); | ||
|
||
println(instanceof(true, Test)); // out: TypeError: expected type "instance" but got "bool" |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
println(typeof(true)); // out: boolean | ||
println(typeof(false)); // out: boolean | ||
println(typeof(true)); // out: bool | ||
println(typeof(false)); // out: bool |
File renamed without changes.
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
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
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