예제 #1
0
 public function test_Ternary()
 {
     $var1 = new Expr\Variable('a', ['type' => Type::array_()]);
     $var2 = new Expr\Variable('b', ['type' => Type::int_()]);
     $var3 = new Expr\Variable('c', ['type' => Type::float_()]);
     $expr = new Expr\Ternary($var1, $var2, $var3);
     $this->infer([$expr]);
     $this->assertTrue($expr->getAttribute('type')->equals(Type::alternatives([Type::int_(), Type::float_()])));
     $expr = new Expr\Ternary($var1, null, $var3);
     $this->infer([$expr]);
     $this->assertTrue($expr->getAttribute('type')->equals(Type::alternatives([Type::array_(), Type::float_()])));
 }