Skip to content

Commit e27e692

Browse files
Eugene Letuchysgolemon
Eugene Letuchy
authored andcommitted
repo mode: check trait requirements after all other traits applied
... since a (textually later) "use ProvidingTrait;" can result in a class implementing an interface and thus satisfy the 'require interface' of a textually earlier "use RequiringTrait;". Reviewed By: @paroski Differential Revision: D1250792
1 parent 5a448d2 commit e27e692

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

hphp/compiler/analysis/class_scope.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,12 @@ void ClassScope::importUsedTraits(AnalysisResultPtr ar) {
861861

862862
// Import any interfaces implemented
863863
tCls->getInterfaces(ar, m_bases, false);
864-
864+
}
865+
for (unsigned i = 0; i < m_usedTraitNames.size(); i++) {
866+
// Requirements must be checked in a separate loop because the
867+
// interfaces required by one trait may be implemented by another trait
868+
// whose "use" appears later in the class' scope
869+
ClassScopePtr tCls = ar->findClass(m_usedTraitNames[i]);
865870
importTraitRequirements(ar, tCls);
866871
}
867872

hphp/test/run

+1-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ function print_success($tests, $options) {
930930
_\\__|__/_
931931
(___/ \\___)
932932
CLOWN
933-
."\n\n";
933+
."\n\n"; /**/
934934
return;
935935
}
936936
print "\nAll tests passed.\n\n".<<<SHIP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
interface IDY {}
4+
5+
trait MyT { require implements IDY; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?hh
2+
require __DIR__.'/require_constraint_repo_ifaces.inc';
3+
4+
trait DYI implements IDY {}
5+
6+
class C {
7+
use MyT; // requires IDY
8+
use DYI; // provides IDY
9+
}
10+
11+
function main() {
12+
$c = new C();
13+
echo 'Done', "\n";
14+
}
15+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Done

0 commit comments

Comments
 (0)