From 478cccebdefea3b7d76a1d9e2acb3047e5729e75 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Fri, 22 Mar 2024 14:02:19 -0400 Subject: [PATCH] Support suppressing issues on definitions --- src/analyzer/file_analyzer.rs | 2 +- .../Enum/duplicateEnumValue/input.hack | 2 ++ .../Enum/duplicateEnumValue/output.txt | 2 +- .../writeImmutableDefinedOnTrait/input.hack | 26 +++++++++++++++++++ .../writeImmutableDefinedOnTrait/output.txt | 2 ++ 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/inference/Immutable/writeImmutableDefinedOnTrait/input.hack create mode 100644 tests/inference/Immutable/writeImmutableDefinedOnTrait/output.txt diff --git a/src/analyzer/file_analyzer.rs b/src/analyzer/file_analyzer.rs index 02a569bd..f18585de 100644 --- a/src/analyzer/file_analyzer.rs +++ b/src/analyzer/file_analyzer.rs @@ -66,7 +66,7 @@ impl<'a> FileAnalyzer<'a> { let statements_analyzer = StatementsAnalyzer::new( &unnamespaced_file_analyzer, &type_resolution_context, - Vec::new(), + Vec::from_iter(self.file_source.comments.iter()), ); let mut context = ScopeContext::new(FunctionContext::new()); diff --git a/tests/inference/Enum/duplicateEnumValue/input.hack b/tests/inference/Enum/duplicateEnumValue/input.hack index b3973783..0bde419a 100644 --- a/tests/inference/Enum/duplicateEnumValue/input.hack +++ b/tests/inference/Enum/duplicateEnumValue/input.hack @@ -3,6 +3,8 @@ enum Suit: string { Diamonds = "d"; Clubs = "c"; Spades = "c"; + /* HAKANA_FIXME[DuplicateEnumValue] */ + Aces = "c"; } enum Color: int { diff --git a/tests/inference/Enum/duplicateEnumValue/output.txt b/tests/inference/Enum/duplicateEnumValue/output.txt index 9ea47240..2384966b 100644 --- a/tests/inference/Enum/duplicateEnumValue/output.txt +++ b/tests/inference/Enum/duplicateEnumValue/output.txt @@ -1,2 +1,2 @@ ERROR: DuplicateEnumValue - input.hack:5:14 - Duplicate enum value for Suit, previously defined by case Clubs -ERROR: DuplicateEnumValue - input.hack:12:14 - Duplicate enum value for Color, previously defined by case Blue +ERROR: DuplicateEnumValue - input.hack:14:14 - Duplicate enum value for Color, previously defined by case Blue diff --git a/tests/inference/Immutable/writeImmutableDefinedOnTrait/input.hack b/tests/inference/Immutable/writeImmutableDefinedOnTrait/input.hack new file mode 100644 index 00000000..4f7d5461 --- /dev/null +++ b/tests/inference/Immutable/writeImmutableDefinedOnTrait/input.hack @@ -0,0 +1,26 @@ +<> +trait T { + public int $b; + public function __construct(int $b) { + $this->b = $b; // ok + } +} + +class A { + use T; + + public function mutate() { + $this->b = 5; // gets flagged + } +} + +<<__EntryPoint>> +function main() { + $a = new A(3); + $a->b = 6; // ok + bar($a); +} + +function bar(A $a): void { + $a->b = 7; // gets flagged +} \ No newline at end of file diff --git a/tests/inference/Immutable/writeImmutableDefinedOnTrait/output.txt b/tests/inference/Immutable/writeImmutableDefinedOnTrait/output.txt new file mode 100644 index 00000000..89b5cb89 --- /dev/null +++ b/tests/inference/Immutable/writeImmutableDefinedOnTrait/output.txt @@ -0,0 +1,2 @@ +ERROR: ImmutablePropertyWrite - input.hack:13:16 - Property A::$b is defined on an immutable class +ERROR: ImmutablePropertyWrite - input.hack:25:9 - Property A::$b is defined on an immutable class