Skip to content

Commit 90d7b5c

Browse files
ottonifacebook-github-bot
authored andcommitted
Allow non-abstract type constants from interfaces to be overriden
Summary: The runtime allows this, and it seems to be the desired behavior for now. Without this diff, HHVM could throw a static-analysis error. Reviewed By: vassilmladenov Differential Revision: D38561777 fbshipit-source-id: 10f60e60732c014fe5897afd87bc5b9e918203c0
1 parent 7c9ac8f commit 90d7b5c

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

hphp/hhbbc/index.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,9 +2515,10 @@ bool build_class_constants(IndexData& index,
25152515

25162516
if ((cns->cls->attrs & AttrInterface ||
25172517
(RO::EvalTraitConstantInterfaceBehavior && (cns->cls->attrs & AttrTrait))) &&
2518-
existing->isAbstract) {
2519-
// because existing has val, this covers the case where it is
2520-
// abstract with default allow incoming to win
2518+
(existing->isAbstract || cns->kind == ConstModifiers::Kind::Type)) {
2519+
// Because existing has val, this covers the case where it is abstract
2520+
// with default allow incoming to win. Also, type constants from
2521+
// interfaces may be overridden even if they're not abstract.
25212522
} else {
25222523
// A constant from an interface or from an included enum collides
25232524
// with an existing constant.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fatal error: C cannot inherit the type constant T from T2, because it was previously inherited from I1 in %s/test/slow/constants/trait_interface_equivalence.php on line 13
1+
Fatal error: C cannot inherit the type constant T from %rT2|C%r, because it was previously inherited from I1 in %s/test/slow/constants/trait_interface_equivalence.php on line 13
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fatal error: B cannot inherit the type constant T from T, because it was previously inherited from A in %s/hphp/test/slow/constants/trait_unsoundness_example.php on line 11
1+
Fatal error: B cannot inherit the type constant T from %rT|B%r, because it was previously inherited from A in %s/hphp/test/slow/constants/trait_unsoundness_example.php on line 11
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?hh
2+
3+
interface I1 {
4+
abstract const type T1;
5+
}
6+
7+
interface I2 extends I1 {
8+
const type T1 = int;
9+
}
10+
11+
interface I3 extends I2 {
12+
const type T1 = int;
13+
}
14+
15+
abstract class C implements I3 {}
16+
17+
<<__EntryPoint>> function main() {
18+
var_dump(C::class);
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
string(1) "C"

0 commit comments

Comments
 (0)