Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow limiting who can inherit/implement a class #1450

Closed
muglug opened this issue Mar 11, 2019 · 2 comments
Closed

Allow limiting who can inherit/implement a class #1450

muglug opened this issue Mar 11, 2019 · 2 comments
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement

Comments

@muglug
Copy link
Collaborator

muglug commented Mar 11, 2019

/**
 * @psalm-inheritors FooClass|BarClass
 */
class BaseClass {}

class FooClass extends BaseClass {
  public function thing(string $s) : void { return $s . "hello"; }
}

class BarClass extends BaseClass {
  public function thing(int $i) : string { return $i . "hello"; }
}

class BazClass extends BaseClass {} // this is an error

function f1(BaseClass $c) : string {
  switch (get_class($c)) {
    case FooClass:class:
      return $c->thing("me");
    case BarClass:class:
      return $c->thing(5);
  }
}

function f2(BaseClass $c) : string { // this is an error as not all paths are met
  switch (get_class($c)) {
    case FooClass:class:
      return $c->thing("me");
  }
}
@muglug muglug added the easy problems Issues that can be fixed without background knowledge of Psalm label Apr 26, 2020
orklah added a commit that referenced this issue May 7, 2023
WIP - Limit inheritance to a subset of classes #1450
@kkmuffme
Copy link
Contributor

Would be nice if there was a wildcard for the namespace, e.g. FooClass of any namespace can extend it

@orklah
Copy link
Collaborator

orklah commented May 30, 2023

This would be a pain to implement for a very niche usage I think.

I'll close this btw, it has been implemented

@orklah orklah closed this as completed May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement
Projects
None yet
Development

No branches or pull requests

3 participants