forked from xtclang/xvm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gene Gleyzer
committed
Sep 12, 2023
1 parent
e67918d
commit 294948c
Showing
2 changed files
with
30 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,24 @@ | ||
module TestSimple { | ||
@Inject Console console; | ||
module TestSimple { | ||
@Inject Console console; | ||
|
||
void run() { | ||
Callback[] callbacks = new Array(); | ||
callbacks.add(new MyCallbackOne()); | ||
callbacks.add(new MyCallbackTwo()); | ||
void run() { | ||
} | ||
|
||
// the line below used to throw TypeMismatch at run-time; it no longer compiles | ||
// Callback[] filtered = callbacks.filter(c -> !c.is(MyCallbackOne)); | ||
Collection<Callback> filtered = callbacks.filter(c -> !c.is(MyCallbackOne)); | ||
for (Callback callback : filtered) { | ||
callback.call(); | ||
} | ||
|
||
for (Callback callback : callbacks.filter(c -> c.is(MyCallbackOne))) { | ||
callback.call(); | ||
} | ||
} | ||
|
||
interface Callback { | ||
void call(); | ||
} | ||
|
||
const MyCallbackOne | ||
implements Callback { | ||
@Override | ||
void call() { | ||
console.print("one"); | ||
} | ||
} | ||
Iterator<Int> test(Int next) { // the name collision used to assert the compiler | ||
return new Iterator<Int>() { | ||
private Int nextValue = next; | ||
private Boolean hasNext = True; | ||
|
||
const MyCallbackTwo | ||
implements Callback { | ||
@Override | ||
void call() { | ||
console.print("two"); | ||
conditional Element next() { | ||
if (hasNext) { | ||
Int value = nextValue; | ||
hasNext = False; | ||
return True, value; | ||
} else { | ||
return False; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} |