language
stringlengths 0
24
| filename
stringlengths 9
214
| code
stringlengths 99
9.93M
|
---|---|---|
PHP | hhvm/hphp/hack/test/lint/is_always_true3.php | <?hh // strict
interface I {
public function f(): void;
}
interface J extends I {}
function test(J $j): void {
if ($j is I) {
$j->f();
}
} |
PHP | hhvm/hphp/hack/test/lint/is_in_loop.php | <?hh // strict
class Foo {}
class Bar extends Foo {}
function test(bool $b, Foo $x): void {
while ($b) {
if ($x is Bar) {
print("x was Bar\n");
}
$x = new Bar();
}
} |
PHP | hhvm/hphp/hack/test/lint/is_non_tautological.php | <?hh // strict
abstract class A {
public function a(): void {}
}
abstract class B extends A {}
class C extends B {
public function c(): void {}
}
interface I {
public function i(): void {}
}
interface J {
public function j(): void {}
}
function test1(B $b): void {
if ($b is C) {
$b->c();
}
}
function test2(C $c): void {
if ($c is I) {
$c->i();
}
}
function test3(I $i): void {
if ($i is C) {
$i->c();
}
}
function test4(I $i): void {
if ($i is J) {
$i->j();
}
} |
PHP | hhvm/hphp/hack/test/lint/lint_internal_class.php | //// def.php
<?hh
new module foo {}
//// use.php
<?hh
module foo;
internal class Foo {
public function foo(): void {
$y = Foo::class;
$y = static::class;
}
}
public class Bar extends Foo {
public function test(): void {
$y = parent::class;
}
} |
PHP | hhvm/hphp/hack/test/lint/missing_override_attribute.php | <?hh // strict
abstract class A {
abstract public function a(): int;
abstract public static function sa(): int;
}
class B extends A {
public function b(): int { return 0; }
public static function sb(): int { return 0; }
}
interface I {
public function i(): num;
public static function si(): num;
}
trait T {
public function t(): int { return 0; }
public static function st(): int { return 0; }
public function foo(): int { return 42; } // avoids triggering Lint[5627]
}
class C extends B {
use T;
// BAD: An "override" of an abstract method requires the annotation
public function a(): int { return 1; }
public static function sa(): int { return 1; }
// BAD: An override of a concrete method requires the annotation
public function b(): int { return 1; }
public static function sb(): int { return 1; }
// BAD: An override of a trait method requires the annotation
public function t(): int { return 1; }
public static function st(): int { return 1; }
}
interface J extends I {
// BAD: In an interface, overriding a method inherited from another interface
// requires the annotation
public function i(): int;
public static function si(): int;
}
class D {
use T;
// BAD: An override of a trait method requires the annotation
private function t(): int { return 1; }
private static function st(): int { return 1; }
} |
PHP | hhvm/hphp/hack/test/lint/msg_null_check.php | <?hh // strict
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*
*/
function takesInt(int $x): void {}
class X {
private ?int $x = null;
public function test(): void {
if($this->x) {
takesInt($this->x);
}
}
} |
PHP | hhvm/hphp/hack/test/lint/nonredundant_generics.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
final class MyList<T> {
public function __construct(public T $item) { }
}
final class C<Tc> {
public function thisisok1<T>(T $x):T { return $x; }
public function thisisok2<T>():void where Tc = MyList<T> { }
public function thisisok3<T>(inout T $_x):void { }
public function thisisok4<T>():(function(inout T):void) {
throw new Exception("E");
}
public function thisisok5<reify T>(T $_x):void { }
public function thisisok6<reify T>():T {
throw new Exception("E");
}
public function thisisok7<<<__Explicit>> T>(T $_x):void { }
public function thisisok8<<<__Explicit>> T>():T {
throw new Exception("E");
}
public function thisisok9<T>(T... $x): T {
throw new Exception("E");
}
}
final class Cov<+TCov> {
public function concat1<T super TCov>(T $_x):vec<T> { return vec[]; }
public function concat2<T>(T $_x):vec<T> where T super TCov { return vec[]; }
}
interface HasFoo {
abstract const type TFoo;
public function getFoo(): this::TFoo;
}
function thisisok<T as HasFoo, TFoo>(T $x): TFoo where TFoo = T::TFoo {
return $x->getFoo();
} |
PHP | hhvm/hphp/hack/test/lint/non_null_check_always_true.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function expect_int(int $_): void {}
function test(int $x): void {
if ($x !== null) {
expect_int($x);
}
} |
PHP | hhvm/hphp/hack/test/lint/non_null_is_check_always_true.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function expect_int(int $_): void {}
function test(int $x): void {
if ($x is nonnull) {
expect_int($x);
}
} |
PHP | hhvm/hphp/hack/test/lint/not_missing_override_attribute.php | <?hh // strict
// These examples should not cause the missing_override_attribute lint error to
// be emitted.
interface I {
public function i(): int;
public static function si(): int;
}
interface J {
public function j(): int;
public static function sj(): int;
}
class B implements J {
public function __construct() {}
}
trait T {
private function t(): int { return 0; }
private static function st(): int { return 0; }
public function foo(): int { return 42; } // avoids triggering Lint[5627]
}
class C extends B implements I {
use T;
// OK: Constructors do not require the annotation
public function __construct() {}
// OK: Implementing an interface does not require the annotation
public function i(): int { return 0; }
public static function si(): int { return 0; }
// OK: Implementing an interface specified by a parent does not require the
// annotation
public function j(): int { return 0; }
public static function sj(): int { return 0; }
}
class D {
private function f(): void {}
}
class E extends D {
// OK: Any method matching to private method of base class does not require the annotation
public function f(): void {}
} |
PHP | hhvm/hphp/hack/test/lint/nullsafe1.php | <?hh // strict
class A {
public function f(): void {}
}
function cond(): bool {
return false;
}
function test(): void {
$x = null;
if (cond()) {
$x = new A();
}
if ($x !== null) {
$x?->f();
}
} |
PHP | hhvm/hphp/hack/test/lint/nullsafe2.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class A {
public int $x = 42;
}
class B {
public string $x = 'answer';
}
function test(bool $c, A $a, B $b): arraykey {
if ($c) {
$ab = $a;
} else {
$ab = $b;
}
return $ab?->x;
} |
PHP | hhvm/hphp/hack/test/lint/nullsafe4.php | <?hh // strict
class C {
public function foo(): D {
return new D();
}
}
class D {}
function test(C $c): D {
return $c?->foo();
} |
PHP | hhvm/hphp/hack/test/lint/nullsafe5.php | <?hh // strict
class A {
public function foo(): void {
}
}
function main(?A $a): void {
$a ?? new A() ?->foo();
} |
PHP | hhvm/hphp/hack/test/lint/nullsafe6.php | <?hh // strict
class MyClass {
public int $x = 0;
}
function foo(MyClass $bar): void {
$bar?->x;
} |
PHP | hhvm/hphp/hack/test/lint/null_check_always_false.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function f(): void {}
function test(int $x): void {
if ($x === null) {
f();
}
} |
PHP | hhvm/hphp/hack/test/lint/null_check_strict.php | <?hh // strict
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*
*/
class X {
private ?int $x;
public function foo(): int {
if ($this->x) {
return $this->x;
}
return 0;
}
} |
PHP | hhvm/hphp/hack/test/lint/null_check_strict2.php | <?hh // strict
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*
*/
class X {
public ?int $x;
public function foo(): int {
$obj = new X();
if($obj->x) {
return $obj->x;
}
return 0;
}
} |
PHP | hhvm/hphp/hack/test/lint/null_check_untyped.php | <?hh
// Copyright 2004-present Facebook. All Rights Reserved.
interface I<+T> {
public function f(): T;
}
function f<T>(I<T> $x): T {
return $x->f();
}
function test($untyped_value): nonnull {
$x = f($untyped_value);
if ($x !== null) {
return $x;
}
return false;
} |
PHP | hhvm/hphp/hack/test/lint/null_is_check_always_false.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function f(): void {}
function test(int $x): void {
if ($x is null) {
f();
}
} |
PHP | hhvm/hphp/hack/test/lint/optional_closed_shape.php | <?hh
function closed_shape(): ?shape('hello' => string) {
return shape('hello' => 'there');
}
function test_closed(): void {
$s = closed_shape();
echo Shapes::idx($s, 'not_a_key'); // error, no lint
$x = $s['not_a_key'] ?? 'bli'; // error, no lint
$s as nonnull;
echo Shapes::idx($s, 'not_a_key'); // error, no lint
echo Shapes::at($s, 'not_a_key'); // throw, error, no lint
echo Shapes::keyExists($s, 'not_a_key'); // error, no lint
echo $s['not_a_key']; // error, no lint
$x = $s['not_a_key'] ?? 'bli'; // error, no lint
}
function open_shape(): ?shape('hello' => string, ...) {
return shape('hello' => 'there');
}
function test_open(): void {
$s = open_shape();
echo Shapes::idx($s, 'not_a_key'); // no error, no lint
$x = $s['not_a_key'] ?? 'bli'; // no error, no lint
$s as nonnull;
echo Shapes::idx($s, 'not_a_key'); // no error, no lint
echo Shapes::at($s, 'not_a_key'); // throw, no error, no lint
echo Shapes::keyExists($s, 'not_a_key'); // no error, no lint
echo $s['not_a_key']; // error, no lint
$x = $s['not_a_key'] ?? 'bli'; // no error, no lint
}
<<__EntryPoint>>
function main(): void {
test_closed();
test_open();
} |
PHP | hhvm/hphp/hack/test/lint/override_trait.php | <?hh
class C {
public function f(): void {}
}
trait TCGood {
require extends C;
<<__Override>>
public function f(): void {
echo "In TCGood\n";
}
}
trait TCBad {
require extends C;
public function f(): void {
echo "In TCBad\n";
}
}
interface I {
public function g(): void;
}
trait TIGood {
require implements I;
public function g(): void {
echo "In TIGood\n";
}
} |
PHP | hhvm/hphp/hack/test/lint/override_trait_methods_plus_implements.php | <?hh
interface MyOtherInterface {}
interface MyInterface {
public function foo(): int;
}
trait MyTrait implements MyInterface {
require implements MyOtherInterface;
public function foo(): int { return 1; }
}
class MyClass {
// We've overridden the method, but we still need the trait because
// it includes `implements MyInterface`.
use MyTrait;
<<__Override>>
public function foo(): int { return 2; }
} |
PHP | hhvm/hphp/hack/test/lint/override_trait_methods_require_class_2.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<file:__EnableUnstableFeatures('require_class')>>
trait T {
require class C;
public function foo(): void {}
public function bar(): void {}
}
class C {
use T;
}
class D extends C {
<<__Override>>
public function foo(): void {}
} |
PHP | hhvm/hphp/hack/test/lint/override_trait_methods_require_implements.php | <?hh
interface MyInterface {
public function foo(): int;
}
trait MyTrait {
require implements MyOtherInterface;
public function bar(): int { return $this->foo(); }
}
class MyClass implements MyInterface {
// This trait is useless, we've overridden all its methods.
use MyTrait;
public function foo(): int { return 1; }
<<__Override>>
public function bar(): int { return 2; }
} |
PHP | hhvm/hphp/hack/test/lint/override_trait_method_require_class.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<file:__EnableUnstableFeatures('require_class')>>
trait T {
require class C;
public function foo(): void {}
public function bar(): void {}
}
class C {
use T;
<<__Override>>
public function foo(): void {}
} |
PHP | hhvm/hphp/hack/test/lint/perf_bad_smells_sgrep.php | <?hh
function test($x) {
array_keys(array_filter(X));
str_replace('_', '-', X);
new URI($X);
URI((string)$X);
URI($X->__toString());
array_keys(array_pull(X, Y));
in_array(A, array_keys(B));
array_unique(array_keys(X));
array_unique(array_filter(X, Y, Z));
} |
PHP | hhvm/hphp/hack/test/lint/pointless_booleans.php | <?hh
function check1 (int $x, int $y, mixed $z1): int {
($x === 1) && true; // pointless
return 1;
}
function check2 (int $x, int $y, mixed $z1): int {
($x === 2) || false; // pointless
return 1;
}
function check3 (int $x, int $y, mixed $z1): int {
($x === 3) && false; // always false
return 1;
}
function check4 (int $x, int $y, mixed $z1): int {
($x > 3) && false; // always false
return 1;
}
function check5 (int $x, int $y, mixed $z1): int {
true || false; // always true
return 1;
}
function check6 (int $x, int $y, mixed $z1): int {
false && ($x === 3); // always false
return 1;
}
function check7 (int $x, int $y, mixed $z1): int {
($x === 3) && ($y === 3); // shouldn't give lint
return 1;
}
function check8 (int $x, int $y, mixed $z1): int {
$x > 3 && false; // always false
return 1;
}
function check9 (int $x, int $y, mixed $z1): int {
$z1 && false; //pointless boolean should not be detected
return 1;
} |
PHP | hhvm/hphp/hack/test/lint/preparables_sgrep.php | <?hh
function test($x, $y, $z) {
gena(varray[A]);
genak(A, new ImmSet($x));
genak(A, B->toArray());
list($a, $b) = await gena(varray[$x, $y]);
list($a, $b, $c) = await gena(varray[$x, $y, $z]);
list($a, $b) = Asio::awaitSynchronously(gena(varray[$x, $y]));
list($a, $b, $c) = Asio::awaitSynchronously(gena(varray[$x, $y, $z]));
return Asio::awaitSynchronously(A);
} |
PHP | hhvm/hphp/hack/test/lint/private_methods.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
abstract class TestDeadPrivateMethod {
// sanity, public/private/protected
public function publicMethodOuter(): string {
return $this->protectedMethod() . $this->publicMethodInner();
}
public function publicMethodInner(): string {
return $this->livePrivateMethod();
}
protected function protectedMethod(): string {
return "Never doubt I love";
}
private function livePrivateMethod(): string {
return "I am alive";
}
private function deadPrivateMethodOuter(): string {
return $this->deadPrivateMethodInner();
}
private function deadPrivateMethodInner(): string {
return "Life's but a walking shadow, signifying nothing.";
}
// recursion
private function deadPrivateMethodSelfRecursion(
int $counter,
): void {
if ($counter > 0) {
$this->deadPrivateMethodSelfRecursion($counter - 1);
}
}
private function deadPrivateMethodMutualRecursion1(
int $counter,
): void {
if ($counter > 0) {
$this->deadPrivateMethodMutualRecursion2($counter - 1);
}
}
private function deadPrivateMethodMutualRecursion2(
int $counter,
): void {
if ($counter > 0) {
$this->deadPrivateMethodMutualRecursion1($counter - 2);
}
}
// static methods
static public function staticPublicMethod(): float {
return self::liveStaticPrivateMethod();
}
static private function liveStaticPrivateMethod(): float {
return 3.1415;
}
static private function deadStaticPrivateMethod(): float {
return 2.7182;
}
// abstract methods
abstract static public function abstractStaticPublicMethod(): float;
}
class FinalTestDeadPrivateMethod extends TestDeadPrivateMethod {
<<__Override>>
final static public function abstractStaticPublicMethod(
): float {
return self::staticPublicMethod();
}
}
trait SomeTrait {
private function liveTraitMethod(): string {
return "Trait methods are always assumed alive, because a class that " .
"uses the trait can access privates methods defined in the trait ".
"but we don't know about the class in Zoncolan call graph ";
}
} |
PHP | hhvm/hphp/hack/test/lint/recursion_no_base_case.php | <?hh
// @format
function foo1(): void {
foo1(); //should produce lint
}
function foo2(): void {
foo2(); //should produce lint
$x = 1;
}
function foo3(): void {
$x = 1; //should produce lint
foo3();
}
function foo4(int $x): void {
foo4($x); //should produce lint
}
function foo5(): void {
foo3(); //should not produce lint
}
async function foo6(): Awaitable<void> {
await foo6(); //should produce lint
}
function test_throw_lint(): Error {
throw test_throw_lint(); // should produce lint
}
//Testing for conditionals
function test_if_return(): int {
$x1 = 2;
if ($x1 == 2) {
return $x1;
}
return test_if_return(); //should not produce lint
}
function test_if_void(): void {
$x1 = 2;
if ($x1 == 2) {
return;
}
test_if_void(); //should not produce lint
}
function test_multiple_base_cases_lint(int $x): int {
if ($x == 1) {
return test_multiple_base_cases_lint($x);
} else if ($x == 2) {
return test_multiple_base_cases_lint(1);
}
return test_multiple_base_cases_lint($x); //should produce lint
}
function test_multiple_base_cases_no_lint(int $x): int {
if ($x == 1) {
return 1;
} else if ($x == 2) {
return test_multiple_base_cases_no_lint(1);
}
return test_multiple_base_cases_no_lint($x); //should not produce lint
}
function test_multiple_base_cases_no_lint_throw(int $x): int {
if ($x == 1) {
throw new Error('error');
} else if ($x == 2) {
return test_multiple_base_cases_no_lint_throw(1);
}
return test_multiple_base_cases_no_lint_throw($x); //should not produce lint
}
function test_multiple_base_cases_lint_throw(int $x): Error {
if ($x == 1) {
throw test_multiple_base_cases_lint_throw($x);
} else if ($x == 2) {
return test_multiple_base_cases_lint_throw(1);
}
return test_multiple_base_cases_lint_throw($x); //should produce lint
}
function test_return_in_else_no_lint(int $x): int {
if ($x == 1) {
return test_return_in_else_no_lint(1);
;
} else if ($x == 2) {
return 2;
}
return test_return_in_else_no_lint($x); //should not produce lint
}
function test_nested_ifs_lint(int $x): int {
if ($x == 1) {
if ($x == 2) {
return test_nested_ifs_lint($x);
}
} else if ($x == 2) {
return test_nested_ifs_lint(1);
}
return test_nested_ifs_lint($x); //should produce lint
}
function test_nested_ifs_no_lint(int $x): int {
if ($x == 1) {
if ($x == 2) {
return $x;
}
} else if ($x == 2) {
return test_nested_ifs_no_lint(1);
}
return test_nested_ifs_no_lint($x); //should not produce lint
}
function test_no_return_no_lint(int $i): void {
if ($i > 0) {
echo "$i";
test_no_return_no_lint($i - 1); //should not produce lint
}
}
class Foo {
public static function bar(): void {
Foo::bar(); //should produce lint
}
public static function bar2(): void {
static::bar2(); //should produce lint
}
public function bar4(): void {
$this->bar4(); //should produce lint
}
public static function bar5(int $x): void {
Foo::bar5($x); //should produce lint
}
public static function returnBar(): int {
return Foo::returnBar(); //should produce lint
}
public static function returnBar2(): int {
return static::returnBar2(); //should produce lint
}
public static function returnBar3(): int {
return self::returnBar3(); //should produce lint
}
public function returnBar4(): int {
return $this->returnBar4(); //should produce lint
}
public async function returnAwaitExpr(): Awaitable<void> {
return await $this->returnAwaitExpr(); //should produce lint
}
public function returnBar5(): int {
$x1 = 2;
if ($x1 == 2) {
return $x1;
}
return $this->returnBar5(); //should not produce lint
}
public function testMultipleBaseCasesLint(int $x): int {
if ($x == 1) {
return $this->testMultipleBaseCasesLint($x);
} else if ($x == 2) {
return $this->testMultipleBaseCasesLint(1);
}
return $this->testMultipleBaseCasesLint($x); //should produce lint
}
public function testMultipleBaseCasesNoLint(int $x): int {
if ($x == 1) {
return 1;
} else if ($x == 2) {
return $this->testMultipleBaseCasesNoLint(1);
}
return $this->testMultipleBaseCasesNoLint($x); //should not produce lint
}
public function testReturnInElseNoLint(int $x): int {
if ($x == 1) {
return $this->testReturnInElseNoLint(1);
;
} else if ($x == 2) {
return 2;
}
return $this->testReturnInElseNoLint($x); //should not produce lint
}
public function testNestedIfsLint(int $x): int {
if ($x == 1) {
if ($x == 2) {
return $this->testNestedIfsLint($x);
}
} else if ($x == 2) {
return $this->testNestedIfsLint(1);
}
return $this->testNestedIfsLint($x); //should produce lint
}
public function testNestedIfsNoLint(int $x): int {
if ($x == 1) {
if ($x == 2) {
return $x;
}
} else if ($x == 2) {
return $this->testNestedIfsNoLint(1);
}
return $this->testNestedIfsNoLint($x); //should not produce lint
}
}
class Test1 {
public static function testfun(): int {
return 1;
}
}
class Test2 {
public function testfun(): int {
return Test1::testfun(); //should not produce lint
}
} |
PHP | hhvm/hphp/hack/test/lint/redundant_cast2.php | <?hh
// Not redundant
function redundant_cast2(mixed $m, arraykey $a, ?string $s): void {
(string) $m;
(float) $m;
(bool) $m;
(int) $m;
(string) $a;
(float) $a;
(bool) $a;
(int) $a;
(string) $s;
(float) $s;
(bool) $s;
(int) $s;
} |
PHP | hhvm/hphp/hack/test/lint/redundant_cast_placeholder.php | <?hh
class C<+T1, T2, -T3> {
public function foo(T3 $_, nothing $n): T1 { return $n; }
}
class D<+T1, -T3> extends C<T1, int, T3> {
public function bar(T3 $_, nothing $n): T1 { return $n; }
}
class E extends D<bool, string> {}
class F<T1, reify T2> {}
function redundant<<<__Explicit>> T1, T2, <<__Explicit>> T3>(
C<int, string, bool> $c1,
C<T1, T2, T3> $c2,
E $e,
F<int, string> $f,
): void {
$c1 as C<_,_,_>;
$c2 as C<_,_,_>;
new C() as C<_,_,_>;
new D() as C<_,_,_>;
new E() as C<_,_,_>;
$e as C<_,_,_>;
$f as F<_, _>;
}
function not_redundant(
F<int, string> $f1,
F<int, string> $f2,
C<int, string, mixed> $c1,
C<int, string, mixed> $c2
): void {
$f1 as F<_, bool>;
$f2 as F<float, bool>;
new C() as E;
new C() as D<_,_>;
new $c1 as E;
new $c2 as D<_,_>;
} |
PHP | hhvm/hphp/hack/test/lint/redundant_generics.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
final class MyList<T> {
public function __construct(public T $item) { }
}
final class Contra<-T> { }
final class Cov<+TCov> {
public function onlycontravariantsuper<T super TCov>(T $_x):void { }
}
interface I { }
final class C<+Tc> {
public function nowhere<T>(int $_x):void { }
public function onlycovariant1<T>(): T {
throw new Exception("a");
}
public function onlycontravariant1<T as I>(T $_x): void { }
public function onlycontravariant2<T>(): Contra<T> {
return new Contra();
}
public function onlycontravariant3<T>(T $_x): Contra<T> {
return new Contra();
}
public function onlycovariant2<T>((function(T):void) $_f) : void { }
}
interface IVCB { }
interface IEMVB<-TVC as IVCB> { }
interface IPRB<-TVC, -T> { }
function blah<
TVC as IVCB,
TEMV as IEMVB<TVC>
>(
vec<IPRB<TVC, TEMV>> $_rules,
):void { }
function mysort<Tv, T as Container<Tv>>(
inout T $_arg,
): bool {
return false;
}
function mysort_where<Tv,T>(inout T $_arg): bool where T as Container<Tv> { return false; } |
PHP | hhvm/hphp/hack/test/lint/redundant_generics_trait.php | <?hh // strict
trait FooTrait {
// We should report the redundant type parameter here.
public function bar<T>(T $_t): void {}
}
// But not here.
class UsesTrait {
use FooTrait;
} |
PHP | hhvm/hphp/hack/test/lint/redundant_generics_type-refinements.php | <?hh
<<file: __EnableUnstableFeatures('type_refinements')>>
interface Box {
abstract const type TVal;
}
function in_param<Tak as arraykey>(
Box with { type TVal = Tak } $_,
): void {}
function in_classname_param<T0 as shape(...)>(
classname<Box with { type TVal = T0 }> $cls,
T0 $s,
): void {}
function returns_num_box_eq_good<T1 as num>(
): Box with { type TVal = T1 } {
while (true) {}
} |
PHP | hhvm/hphp/hack/test/lint/redundant_mixed_option.php | <?hh // strict
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*
*/
async function redundant_mixed_option(): Awaitable<?mixed> {
return null;
} |
PHP | hhvm/hphp/hack/test/lint/redundant_option_mixed.php | <?hh
class C<T>
function g<T>(): void {}
function f<T>(): void {
g<?mixed>();
new C<?mixed>();
} |
PHP | hhvm/hphp/hack/test/lint/redundant_option_mixed_expression_trees.php | <?hh
<<file:__EnableUnstableFeatures('expression_trees')>>
function redundant_option_mixed_expression_trees(): void {
ExampleDsl`(?mixed $x) ==> {}`;
} |
PHP | hhvm/hphp/hack/test/lint/redundant_option_mixed_expression_trees_virtualized.php | <?hh
<<file:__EnableUnstableFeatures('expression_trees')>>
function redundant_option_mixed_expression_trees_virtualized(): void {
ExampleDsl`(?mixed $x) ==> {}`;
} |
PHP | hhvm/hphp/hack/test/lint/redundant_option_null.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function redundant_option_null(): ?null {
return null;
} |
PHP | hhvm/hphp/hack/test/lint/redundant_unsafe_cast1.php | <?hh
type S = shape('a' => int, 'b' => bool);
newtype NS = shape('a' => int, 'b' => bool);
class C {
const type TCShape = shape('a' => int, 'b' => bool);
}
function redundant_unsafe_casts(string $str, shape('a' => int, 'b' => bool) $s): void {
HH\FIXME\UNSAFE_CAST<arraykey, string>($str);
HH\FIXME\UNSAFE_CAST<shape(...), S>($s);
HH\FIXME\UNSAFE_CAST<NS, S>($s);
HH\FIXME\UNSAFE_CAST<shape(...), NS>($s);
HH\FIXME\UNSAFE_CAST<C::TCShape, NS>($s);
HH\FIXME\UNSAFE_CAST<shape(...), C::TCShape>($s);
HH\FIXME\UNSAFE_CAST<S, C::TCShape>($s);
} |
PHP | hhvm/hphp/hack/test/lint/redundant_unsafe_cast2.php | <?hh
type S = shape('a' => int, 'b' => bool);
newtype NS = shape('a' => int, 'b' => bool);
class C {
const type TCShape = shape('a' => int, 'b' => bool);
}
function not_redundant_unsafe_casts(arraykey $str, shape('a' => int, 'b' => bool, 'c' => float) $s): void {
HH\FIXME\UNSAFE_CAST<arraykey, string>($str);
HH\FIXME\UNSAFE_CAST<shape(...), S>($s);
HH\FIXME\UNSAFE_CAST<NS, S>($s);
HH\FIXME\UNSAFE_CAST<shape(...), NS>($s);
HH\FIXME\UNSAFE_CAST<C::TCShape, NS>($s);
HH\FIXME\UNSAFE_CAST<shape(...), C::TCShape>($s);
HH\FIXME\UNSAFE_CAST<S, C::TCShape>($s);
} |
PHP | hhvm/hphp/hack/test/lint/redundant_unsafe_cast3.php | final class C {
const type TWut = shape('a'=>int,'b'=>float,'c'=>bool);
}
function foo(C::TWut $_): void {}
function bar(
shape('a'=>int,'b'=>float,...) $x,
) : void {
foo(HH\FIXME\UNSAFE_CAST<shape(...),C::TWut>($x));
foo(HH\FIXME\UNSAFE_CAST< shape('a'=>int,'b'=>float,...),C::TWut>($x));
} |
PHP | hhvm/hphp/hack/test/lint/reundant_cast1.php | <?hh
function redundant_int_casts(int $i): void {
(int) $i;
(int) 42;
(int) 10 + 100;
}
function redundant_string_casts(string $s): void {
(string) $s;
(string) 'hello';
(string) 'hello'.'bye';
}
function redundant_float_casts(float $f): void {
(float) $f + 42; // Redundant due to $f
(float) ($f + 42); // Redundant due to implicit coercion
} |
PHP | hhvm/hphp/hack/test/lint/sketchy_null_check_enum.php | //// file1.php
<?hh // strict
enum Foo : int {
ONE = 1;
TWO = 2;
}
//// file2.php
<?hh // strict
function test(?Foo $x): void {
if ($x) {
}
} |
PHP | hhvm/hphp/hack/test/lint/sketchy_null_check_newtype.php | //// file1.php
<?hh // strict
newtype Foo as int = int;
//// file2.php
<?hh // strict
function test(?Foo $x): void {
if ($x) {
}
} |
PHP | hhvm/hphp/hack/test/lint/sketchy_null_check_nullable_newtype.php | //// file1.php
<?hh // strict
newtype Foo as ?int = ?int;
//// file2.php
<?hh // strict
function test(Foo $x): void {
if ($x) {
}
} |
PHP | hhvm/hphp/hack/test/lint/sketchy_null_check_nullable_obj.php | <?hh
// Copyright 2004-present Facebook. All Rights Reserved.
class A {}
function noop(): void {}
function test(?A $x): void {
if ($x) {
noop();
}
} |
PHP | hhvm/hphp/hack/test/lint/sketchy_null_hiding_under_unresolved2.php | <?hh // strict
function f(bool $b, ?int $x): void {
$y = null;
if ($b) {
$y = $x;
}
if ($y) {
}
} |
PHP | hhvm/hphp/hack/test/lint/sketchy_null_hiding_under_unresolved3.php | <?hh // strict
function f(bool $b, int $x): void {
$y = null;
if ($b) {
$y = $x;
}
if ($y) {
}
} |
PHP | hhvm/hphp/hack/test/lint/switch_bad.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function test1(float $x): void {
switch ($x) {
case 'foo': return;
}
}
class A {}
class B {}
function test2(A $x): void {
switch ($x) {
case new B(): return;
}
} |
PHP | hhvm/hphp/hack/test/lint/switch_exhaustiveness_bad.php | <?hh
<<file: __EnableUnstableFeatures('union_intersection_type_hints')>>
class C {}
function bad_class(C $c): void {
switch ($c) {
case new C(): return;
}
}
function bad_int(int $i): void {
switch ($i) {
case 42: return;
case 24: return;
}
}
function bad_string(string $s): void {
switch ($s) {
case "hi": return;
case "hello": return;
}
}
function bad_arraykey(arraykey $s): void {
switch ($s) {
case "hi": return;
case 42: return;
}
}
interface I {}
interface J {}
function bad_intersection((I & J) $o1, (I & J) $o2): void {
switch ($o1) {
case $o2: return;
}
}
function bad_union((bool | string) $s): void {
switch ($s) {
case true: return;
}
} |
PHP | hhvm/hphp/hack/test/lint/switch_exhaustiveness_good.php | <?hh
<<file: __EnableUnstableFeatures('union_intersection_type_hints')>>
function good_mixed(mixed $m): void {
switch ($m) {
case 1: return;
}
}
final class C {}
function good_final_class(C $c): void {
switch ($c) {
case new C(): return;
}
}
function good_bool(bool $b): void {
switch ($b) {
case true: return;
case false: return;
}
}
function good_string(string $s): void {
switch ($s) {
case "hi": return;
case "hello": return;
default: return;
}
}
function good_arraykey(arraykey $s): void {
switch ($s) {
case "hi": return;
case 42: return;
default: return;
}
}
/*
function good_intersection((bool & arraykey) $s): void {
switch ($s) {
case true: return;
}
}
*/
function good_union((bool | C) $s): void {
switch ($s) {
case true: return;
}
} |
PHP | hhvm/hphp/hack/test/lint/switch_exhaustiveness_good2.php | <?hh
enum E : string as string {
A = "A";
B = "B";
}
class C {
public static function getE(): E {
return E::A;
}
}
function test(vec<int> $_):int {
$e = C::getE();
switch ($e) {
case E::A : return 1;
case E::B : return 2;
}
} |
PHP | hhvm/hphp/hack/test/lint/switch_good.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function test1(num $x): void {
switch ($x) {
case 42: return;
case 3.14: return;
default: return;
}
}
function test2(arraykey $x): void {
switch ($x) {
case 42: return;
case 'foo': return;
default: return;
}
}
class C {}
function test3(vec<C> $x): void {
switch ($x) {
case vec[]: return;
case vec[new C()]: return;
default: return;
}
} |
PHP | hhvm/hphp/hack/test/lint/T148500367.php | <?hh
function essential_nonnull1(?int $key, vec<vec<int>> $v): void {
// redundant nonnull shouldn't fire
$v[$key as nonnull][] = 42;
}
function essential_nonnull2(?int $key, vec<vec<int>> $v): void {
// redundant nonnull shouldn't fire
$v[$key as nonnull][42] = 42;
} |
PHP | hhvm/hphp/hack/test/lint/truthiness_literal_null.php | <?hh // strict
function test(): void {
$x = null;
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_01.php | <?hh // strict
function test(int $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_02.php | <?hh // strict
class Foo {}
function test(Foo $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_03.php | <?hh // strict
function test(Traversable<int> $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_04.php | <?hh // strict
function test(Container<int> $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_05.php | <?hh // strict
function test(SimpleXMLElement $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_06.php | <?hh // strict
class NullObject extends SimpleXMLElement {}
function test(NullObject $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_07.php | <?hh // strict
function test(array<int> $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_08.php | <?hh // strict
function test(vec<int> $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_09.php | <?hh // strict
function test(dict<string, int> $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_10.php | <?hh // strict
function test(keyset<int> $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_11.php | <?hh // strict
function test(bool $b, Traversable<int> $t, vec<int> $v): void {
$x = $b ? $t : $v;
// Error--$t may be an always-truthy value like a user-defined Iterator.
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_12.php | <?hh // strict
class Foo {}
function test(bool $b, Foo $f1, ?Foo $f2): void {
$x = $b ? $f1 : $f2;
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_13.php | <?hh // strict
function test(arraykey $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_14.php | <?hh // strict
function test(bool $b, string $s): void {
$x = $b ? $s : $b;
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_15.php | <?hh // strict
function test(Iterable<int> $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_16.php | <?hh // strict
class Foo implements Iterator<int> {
public function current(): int {
return 0;
}
public function next(): void {}
public function rewind(): void {}
public function valid(): bool {
return true;
}
}
class Bar extends Foo {}
function test(Bar $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_17.php | <?hh // strict
class Foo implements Iterator<int> {
public function current(): int {
return 0;
}
public function next(): void {}
public function rewind(): void {}
public function valid(): bool {
return true;
}
}
class Bar extends Foo {}
function test(bool $b, Bar $bar): void {
$x = $b ? $bar : $b;
// $x : (Bar | bool). Even though Bar is always-truthy, we permit this check
// because bool is possibly-falsy.
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_18.php | <?hh // strict
function test(Pair<int, int> $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_19.php | <?hh // strict
function test(Stringish $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_20.php | <?hh // strict
class C implements StringishObject{
public function __toString(): string { return ''; }
}
function test(C $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_21.php | <?hh // strict
type A = shape(?'a' => int);
function test(A $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_22.php | <?hh // strict
type A = shape('a' => int, ?'b' => int);
function test(A $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_23.php | <?hh // strict
function foo(XHPChild $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/truthiness_test_tuple.php | <?hh // strict
function test((bool, bool) $x): void {
if ($x) {
do_something();
}
}
function do_something(): void {} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_lower_bound1.php | <?hh
function unsafe_cast_lower_bound1(mixed $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // No lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_lower_bound2.php | <?hh
function unsafe_cast_lower_bound2(string $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // Lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_lower_bound3.php | <?hh
function unsafe_cast_lower_bound3(shape('my_integer' => int, 'my_string' => string, 'my_bool' => bool) $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // Lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_lower_bound4.php | <?hh
function f(arraykey $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // Lint that mixed is too loose
}
function g(num $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // Lint that mixed is too loose
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_lower_bound5.php | <?hh
function unsafe_cast_lower_bound5(?int $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // No lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_lower_bound_6.php | <?hh
class StopLintFromFiring{}
abstract class C {
abstract const type TFoo as num;
abstract public function get(): this::TFoo;
public function takesString(string $x): void {}
public function test(C $c): void {
// $c->get() : <expr#1>::TFoo
$this->takesString(HH\FIXME\UNSAFE_CAST<mixed,string>($c->get()));
}
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_nondenotable_lower_bound.php | <?hh
<<file: __EnableUnstableFeatures('union_intersection_type_hints')>>
function unsafe_cast_nondenotable_lower_bound((int | bool) $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // No lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_nondenotable_lower_bound2.php | <?hh
function unsafe_cast_nondenotable_lower_bound2(/* Tany */ $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // No lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_nondenotable_lower_bound3.php | <?hh
<<file: __EnableUnstableFeatures('union_intersection_type_hints')>>
function unsafe_cast_nondenotable_lower_bound3(?(int | bool) $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // No lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_nondenotable_lower_bound4.php | <?hh
<<file: __EnableUnstableFeatures('union_intersection_type_hints')>>
function unsafe_cast_nondenotable_lower_bound4(shape('x' => ?(int | bool), 'y' => bool) $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // No lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_nondenotable_lower_bound5.php | <?hh
<<file: __EnableUnstableFeatures('union_intersection_type_hints')>>
function unsafe_cast_nondenotable_lower_bound5(Vector<(int | bool)> $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // No lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_nondenotable_lower_bound6.php | <?hh
<<file: __EnableUnstableFeatures('union_intersection_type_hints')>>
function unsafe_cast_nondenotable_lower_bound6(((int | bool),string) $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, int>($m); // No lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_nondenotable_lower_bound7.php | <?hh
<<file: __EnableUnstableFeatures('union_intersection_type_hints')>>
function unsafe_cast_nondenotable_lower_bound7((function((int | bool)): string) $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, (function(mixed): string)>($m); // No lint
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_nondenotable_lower_bound8.php | <?hh
function unsafe_cast_nondenotable_lower_bound8(mixed $m): void {
if($m is Map<_,_>) {
\HH\FIXME\UNSAFE_CAST<mixed, Map<int,string>>($m); // No lint
}
} |
PHP | hhvm/hphp/hack/test/lint/unsafe_cast_upper_bound.php | <?hh
function unsafe_cast_upper_bound(mixed $m): void {
\HH\FIXME\UNSAFE_CAST<mixed, nothing>($m); // Lint
} |
PHP | hhvm/hphp/hack/test/lint/valid_equality_check.php | <?hh
function takes_int(int $x): void {}
function untyped() { return null; }
function test(vec<int> $v): void {
$x = $v[0] > 0 ? $v[0] : untyped();
if ($x !== null) {
takes_int($x);
}
} |
PHP | hhvm/hphp/hack/test/lint/valid_equality_check_in_loop.php | <?hh // strict
function test(bool $b, arraykey $x): void {
while ($b) {
if ($x === 's') {
print("x was s\n");
}
$x = 5;
}
print("$x\n");
}
// Avoid lint error about file defining only one function
function dummy() {} |
PHP | hhvm/hphp/hack/test/lint/valid_interface_equality_check1.php | <?hh // strict
interface A {}
interface B {}
class C implements A, B {}
function test(A $a, B $b): void {
// It is possible for this comparison to evaluate to true even though there is
// no subtyping relationship between A and B, since C exists.
// We don't have a simple way of determining whether such a class exists at
// lint time, so we don't warn about comparisons between two interface types.
if ($a === $b) {
var_dump($a);
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.