2014-02-15 11:36:01 -08:00
|
|
|
class Foo {
|
2015-09-01 08:16:04 -07:00
|
|
|
construct new() {}
|
2014-04-03 07:48:19 -07:00
|
|
|
static bar { true }
|
|
|
|
|
static baz { 1 }
|
2014-02-15 11:36:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Condition precedence.
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print(true ? 1 : 2) // expect: 1
|
|
|
|
|
System.print((true) ? 1 : 2) // expect: 1
|
|
|
|
|
System.print([true][0] ? 1 : 2) // expect: 1
|
|
|
|
|
System.print(Foo.bar ? 1 : 2) // expect: 1
|
|
|
|
|
System.print(3..4 ? 1 : 2) // expect: 1
|
|
|
|
|
System.print(3 * 4 ? 1 : 2) // expect: 1
|
|
|
|
|
System.print(3 + 4 ? 1 : 2) // expect: 1
|
|
|
|
|
System.print(true || false ? 1 : 2) // expect: 1
|
|
|
|
|
System.print(!false ? 1 : 2) // expect: 1
|
|
|
|
|
System.print(~0 ? 1 : 2) // expect: 1
|
|
|
|
|
System.print(3 is Num ? 1 : 2) // expect: 1
|
|
|
|
|
System.print(Foo.new() ? 1 : 2) // expect: 1
|
2014-02-15 11:36:01 -08:00
|
|
|
|
|
|
|
|
var a = 0
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print(a = 3 ? 1 : 2) // expect: 1
|
|
|
|
|
System.print(a) // expect: 1
|
2014-02-15 11:36:01 -08:00
|
|
|
|
|
|
|
|
// Then branch precedence.
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print(true ? (1) : 2) // expect: 1
|
|
|
|
|
System.print(true ? [1][0] : 2) // expect: 1
|
|
|
|
|
System.print(true ? Foo.baz : 2) // expect: 1
|
|
|
|
|
System.print(true ? 3..4 : 2) // expect: 3..4
|
|
|
|
|
System.print(true ? 3 * 4 : 2) // expect: 12
|
|
|
|
|
System.print(true ? 3 + 4 : 2) // expect: 7
|
|
|
|
|
System.print(true ? 1 || false : 2) // expect: 1
|
|
|
|
|
System.print(true ? !true : 2) // expect: false
|
|
|
|
|
System.print(true ? ~0 : 2) // expect: 4294967295
|
|
|
|
|
System.print(true ? 3 is Bool : 2) // expect: false
|
|
|
|
|
System.print(true ? Foo.new() : 2) // expect: instance of Foo
|
2014-02-15 11:36:01 -08:00
|
|
|
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print(true ? a = 5 : 2) // expect: 5
|
|
|
|
|
System.print(a) // expect: 5
|
2014-02-15 11:36:01 -08:00
|
|
|
|
|
|
|
|
// Else branch precedence.
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print(false ? 1 : (2)) // expect: 2
|
|
|
|
|
System.print(false ? 1 : [2][0]) // expect: 2
|
|
|
|
|
System.print(false ? 2 : Foo.baz) // expect: 1
|
|
|
|
|
System.print(false ? 1 : 3..4) // expect: 3..4
|
|
|
|
|
System.print(false ? 1 : 3 * 4) // expect: 12
|
|
|
|
|
System.print(false ? 1 : 3 + 4) // expect: 7
|
|
|
|
|
System.print(false ? 1 : 2 || false) // expect: 2
|
|
|
|
|
System.print(false ? 1 : !false) // expect: true
|
|
|
|
|
System.print(false ? 1 : ~0) // expect: 4294967295
|
|
|
|
|
System.print(false ? 1 : 3 is Num) // expect: true
|
|
|
|
|
System.print(false ? 1 : Foo.new()) // expect: instance of Foo
|
2014-02-15 11:36:01 -08:00
|
|
|
|
|
|
|
|
// Associativity.
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print(true ? 2 : true ? 4 : 5) // expect: 2
|
|
|
|
|
System.print(false ? 2 : true ? 4 : 5) // expect: 4
|