Skip to content

Only one intersection with static is allowed #1661

@muglug

Description

@muglug
interface I1 {
  public function someMethod();
}

interface I2 {
  public function someOtherMethod();
}

class Foo {
	/**
	 * @return I1&static
	 */
	public function bar() {
		if ($this instanceof I1) {
			return $this;
		}
		
		throw new \Exception('bad');
	}
	
	/**
	 * @return I2&static
	 */
	public function bat() {
		if ($this instanceof I2) {
			return $this;
		}
		
		throw new \Exception('bad');
	}
}

$a = (new Foo)->bar();
$b = $a->bat();
$b->someMethod();
$b->someOtherMethod();

Expected: No issue (these functions should allow composition so that $b has type I1&I2&Foo)
Actual: An issue - $b has type I2&Foo

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions