Skip to content

Commit

Permalink
Fix unnecessary type alias issues
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 5, 2024
1 parent 7c88b77 commit 37ccff7
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/code_info/t_atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1698,20 +1698,6 @@ pub fn populate_atomic_type(
force,
);
}
TAtomic::TTypeAlias {
type_params: Some(ref mut type_params),
..
} => {
for type_param in type_params {
populate_union_type(
type_param,
codebase_symbols,
reference_source,
symbol_references,
force,
);
}
}
TAtomic::TVec {
ref mut type_param,
ref mut known_items,
Expand Down Expand Up @@ -1739,17 +1725,24 @@ pub fn populate_atomic_type(
}
TAtomic::TNamedObject {
name,
type_params: Some(ref mut type_params),
ref mut type_params,
..
}
| TAtomic::TTypeAlias {
name,
ref mut type_params,
..
} => {
for type_param in type_params {
populate_union_type(
type_param,
codebase_symbols,
reference_source,
symbol_references,
force,
);
if let Some(type_params) = type_params {
for type_param in type_params {
populate_union_type(
type_param,
codebase_symbols,
reference_source,
symbol_references,
force,
);
}
}

match reference_source {
Expand Down
5 changes: 5 additions & 0 deletions tests/diff/classOnlyReferencedInAnotherProperty/a/bar.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<<__EntryPoint>>
function main() {
$a = new A("hello");
echo $a->value;
}
8 changes: 8 additions & 0 deletions tests/diff/classOnlyReferencedInAnotherProperty/a/foo.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
final class A<T> {
public ?B<T> $b = null;
public function __construct(public T $value) {}
}

final class B<T> {
public function __construct(public T $value) {}
}
5 changes: 5 additions & 0 deletions tests/diff/classOnlyReferencedInAnotherProperty/b/bar.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<<__EntryPoint>>
function main() {
$a = new A("bello");
echo $a->value;
}
8 changes: 8 additions & 0 deletions tests/diff/classOnlyReferencedInAnotherProperty/b/foo.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
final class A<T> {
public ?B<T> $b = null;
public function __construct(public T $value) {}
}

final class B<T> {
public function __construct(public T $value) {}
}
2 changes: 2 additions & 0 deletions tests/diff/classOnlyReferencedInAnotherProperty/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ERROR: UnusedPublicOrProtectedProperty - foo.hack:2:46 - Unused public or protected property ApiResourcePermissions::$experiment
ERROR: UnusedPublicOrProtectedProperty - foo.hack:7:39 - Unused public or protected property ApiResourcePermissionsExperiment::$value
8 changes: 8 additions & 0 deletions tests/diff/invalidateShapesIdx/a/bar.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<<__EntryPoint>>
function main() {
bar(shape('a' => 10, 'b' => 'a'));
}

function bar(foo_t $foo) {
echo Shapes::idx($foo, 'b', null);
}
4 changes: 4 additions & 0 deletions tests/diff/invalidateShapesIdx/a/foo.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type foo_t = shape(
'a' => int,
?'b' => string,
);
8 changes: 8 additions & 0 deletions tests/diff/invalidateShapesIdx/b/bar.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<<__EntryPoint>>
function main() {
bar(shape('a' => 10, 'b' => 'a'));
}

function bar(foo_t $foo) {
echo Shapes::idx($foo, 'b', null);
}
4 changes: 4 additions & 0 deletions tests/diff/invalidateShapesIdx/b/foo.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type foo_t = shape(
'a' => int,
'b' => string,
);
1 change: 1 addition & 0 deletions tests/diff/invalidateShapesIdx/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR: UnnecessaryShapesIdx - bar.hack:7:10 - The field 'b' is always present on the shape -- consider using $foo['b'] instead

0 comments on commit 37ccff7

Please sign in to comment.