Skip to content

Commit c1bd05a

Browse files
Nick Bentonfacebook-github-bot
authored andcommitted
[inferhack] test case for changes to hackc intended to make constants in traits work properly
Reviewed By: davidpichardie Differential Revision: D62647632 Privacy Context Container: L1208441 fbshipit-source-id: a0b9c7a34e39db1f932a8ff1a7dd7e4de828543d
1 parent 3a5c261 commit c1bd05a

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

infer/tests/codetoanalyze/hack/pulse/constinit.hack

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,28 @@ class D extends C {
2525
const int Dc = 2;
2626
}
2727

28+
// a more complex situation that really happens
29+
trait T1 {
30+
const int INDEX = C1::INDEX;
31+
}
32+
33+
class C1 {
34+
use T2;
35+
}
36+
37+
trait T2 implements I1 {}
38+
39+
interface I1 extends I2 {}
40+
41+
interface I2 {
42+
const int INDEX = 1;
43+
}
44+
2845
class Tester {
29-
public static async function mainOK(): Awaitable<void> {
46+
public static async function mainOK(classname<C> $c): Awaitable<void> {
3047
$d = D::Dc;
3148
// at this point we should have called, and marked as
32-
// called, C$static._86init
49+
// called, C$static._86constinit
3350
// So the subsequent access to C::Cc shouldn't call constinit first
3451
$c = C::Cc;
3552
// next bit shows we're dealing with constants in interfaces properly
@@ -41,4 +58,14 @@ class Tester {
4158
return; // UAA error
4259
};
4360
}
61+
62+
// no longer an FP
63+
public static async function main2OK(): Awaitable<void> {
64+
if (T1::INDEX === 1) {
65+
return; // should always happen
66+
}
67+
$_ = async {
68+
return; // UAA error, should be unreachable
69+
};
70+
}
4471
}

0 commit comments

Comments
 (0)