Skip to content

Commit

Permalink
1000iq fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Jul 24, 2024
1 parent d5db9fe commit 8df655a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 52 deletions.
72 changes: 22 additions & 50 deletions src/tests/exprtype/exprtype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2201,72 +2201,44 @@ function f() {
runExprTypeTest(t, &exprTypeTestParams{code: code})
}

func TestArrayTypesWithUnpack_Primitives(t *testing.T) {
func TestArrayTypesWithUnpackPrimitives(t *testing.T) {
code := `<?php
declare(strict_types = 1);
function f() {
// with int type
$a = [1, 2, 3];
$b = [0, ...$a];
exprtype($b, "int[]");
$a = 1;
$b = [...$a];
exprtype($b, "mixed");
// with float type
$a1 = [1.1, 2.2, 3.3];
$b1 = [0.0, ...$a1];
exprtype($b1, "float[]");
$a1 = 1.1;
$b1 = [...$a1];
exprtype($b1, "mixed");
// with string type
$a2 = ["a", "b", "c"];
$b2 = ["d", ...$a2];
exprtype($b2, "string[]");
$a2 = "a";
$b2 = [...$a2];
exprtype($b2, "mixed");
// with bool type
$a3 = [true, false, true];
$b3 = [false, ...$a3];
exprtype($b3, "bool[]");
$a3 = true;
$b3 = [...$a3];
exprtype($b3, "mixed");
// mixed types
$a4 = [1, "a", 3.3, true];
$b4 = ["start", ...$a4];
exprtype($b4, "mixed[]");
// null
$a4 = null;
$b4 = [...$a4];
exprtype($b4, "mixed");
// with two unpack
$a5 = [1, 2, 3];
$b5 = [4, 5, 6];
$c5 = [...$a5, ...$b5];
exprtype($c5, "int[]");
// with two unpack with different types
$a6 = [1, 2, 3];
$c6 = [...$a6, ...$a2];
exprtype($c6, "mixed[]");
// one unpack
$a7 = [true, false, true];
$b7 = [...$a7];
exprtype($b7, "bool[]");
// with two unpack and just type
$a8 = [1.1, 2.2, 3.3];
$b8 = [4.4, 5.5, 6.6];
$c8 = [...$a8, 7.7, ...$b8];
exprtype($c8, "float[]");
// class
class Foo {}
$a5 = new Foo();
$b5 = [...$a5];
exprtype($b5, "mixed");
}
`
runExprTypeTest(t, &exprTypeTestParams{code: code})
}

// @see issue1214
func TestArrayTypesWithUnpackNullNegative(t *testing.T) {
linttest.SimpleNegativeTest(t, `<?php
declare(strict_types = 1);
function test() {
$special_items = null;
$_ = [...$special_items];
}`)
}

func TestPropertyTypeHints(t *testing.T) {
code := `<?php
class Too {}
Expand Down
6 changes: 5 additions & 1 deletion src/types/lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,12 @@ func FormatSimpleType(s string) (res string) {
return s
}

func IsAfterWMaxed(typ string) (res bool) {
return typ == "" || typ[0] >= WMax
}

func FormatType(s string) (res string) {
if s == "" || s[0] >= WMax {
if IsAfterWMaxed(s) {
return FormatSimpleType(s)
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (m Map) LazyArrayElemType() Map {
mm := make(map[string]struct{}, m.Len())
for typ := range m.m {
// TODO: https://github.com/VKCOM/noverify/issues/1227
if typ == "null" {
if IsAfterWMaxed(typ) {
break
}

Expand Down

0 comments on commit 8df655a

Please sign in to comment.