Skip to content

Commit

Permalink
Implementations of abstract methods can have supertype parameter types
Browse files Browse the repository at this point in the history
Summary:
Currently the case if `force_hh` is on. Make it true for any subclasses in Hack, rather than PHP.

Going to put up a separate diff RE this only applying to abstract functions.

refs #8256

Reviewed By: swtaarrs

Differential Revision: D8868379

fbshipit-source-id: 83f749139c610e6b0546695b6090f0970bf302b5
  • Loading branch information
fredemmott authored and hhvm-bot committed Jul 17, 2018
1 parent 0bcc1e9 commit 9e99004
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hphp/runtime/vm/type-constraint.cpp
Expand Up @@ -194,7 +194,8 @@ bool TypeConstraint::compat(const TypeConstraint& other) const {
const Class* cls = Unit::lookupClass(m_typeName); const Class* cls = Unit::lookupClass(m_typeName);
const Class* otherCls = Unit::lookupClass(other.m_typeName); const Class* otherCls = Unit::lookupClass(other.m_typeName);


return cls && otherCls && cls == otherCls; return cls && otherCls && (isHHType() ? otherCls->classof(cls)
: cls == otherCls);
} }


return false; return false;
Expand Down
22 changes: 22 additions & 0 deletions hphp/test/slow/class_method/abstract_variance.php
@@ -0,0 +1,22 @@
<?hh // strict

class ParamBase {
}

class ParamSub extends ParamBase {
}

abstract class ImplBase {
abstract public function doStuff(ParamSub $_): void;
}

class ImplSub extends ImplBase {
public function doStuff(ParamBase $_): void {
}
}

function main(): void {
(new ImplSub())->doStuff(new ParamSub());
}

main();
Empty file.

0 comments on commit 9e99004

Please sign in to comment.