Skip to content

Commit

Permalink
Merge pull request #4328 from simonvonhackewitz/fix_record_usage_error
Browse files Browse the repository at this point in the history
ast: fix error when recording usage of fields
  • Loading branch information
michaellilltokiwa authored Nov 30, 2024
2 parents 14a5cf4 + 103df4d commit 7fec268
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
23 changes: 13 additions & 10 deletions src/dev/flang/ast/AbstractCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,20 @@ Call typeCall(SourcePosition p, Resolution res, AbstractFeature that)
*/
public void recordUsage(Set<AbstractFeature> usages)
{
var feat = calledFeature();

// don't collect features that should never be warned about, see Feature.java for reasons
if (feat.kind() == AbstractFeature.Kind.Field
&& feat.visibility().eraseTypeVisibility() != Visi.PUB
&& !feat.featureName().isInternal()
&& !feat.outer().featureName().isInternal()
&& !feat.featureName().isNameless()
&& !feat.isArgument())
if (!(this instanceof Call c) || c.calledFeatureKnown())
{
usages.add(feat);
var feat = calledFeature();

// don't collect features that should never be warned about, see Feature.java for reasons
if (feat.kind() == AbstractFeature.Kind.Field
&& feat.visibility().eraseTypeVisibility() != Visi.PUB
&& !feat.featureName().isInternal()
&& !feat.outer().featureName().isInternal()
&& !feat.featureName().isNameless()
&& !feat.isArgument())
{
usages.add(feat);
}
}
}

Expand Down
28 changes: 14 additions & 14 deletions tests/choice_negative/choice_negative.fz.expected_err
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,34 @@ Target feature: 'choice_negative.instantiate2'
In call: 'MyChoice'


--CURDIR--/choice_negative.fz:137:30: error 10: Could not find called feature
--CURDIR--/choice_negative.fz:170:21: error 10: Ambiguous assignment to 'choice choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.A choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.B' from 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.C'
_ choice A B := C // 36. should flag an error, Ambiguous assignment to ...
--------------------^
'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.C' is assignable to 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.A', 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.B'


--CURDIR--/choice_negative.fz:171:21: error 11: Ambiguous assignment to 'choice choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.A choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.B' from 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.C'
t choice A B => C // 37. should flag an error, Ambiguous assignment to ...
--------------------^
'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.C' is assignable to 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.A', 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.B'


--CURDIR--/choice_negative.fz:137:30: error 12: Could not find called feature
x bool : choice i64 bool := true // 27. should flag an error, choice feature must not be field
-----------------------------^^
Feature not found: 'prefix :=' (no arguments)
Target feature: 'bool'
In call: ':= true'


--CURDIR--/choice_negative.fz:140:25: error 11: Could not find called feature
--CURDIR--/choice_negative.fz:140:25: error 13: Could not find called feature
x : choice i64 bool := true // 28. should flag an error, choice feature must not be field
------------------------^^
Feature not found: 'prefix :=' (no arguments)
Target feature: 'bool'
In call: ':= true'


--CURDIR--/choice_negative.fz:170:21: error 12: Ambiguous assignment to 'choice choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.A choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.B' from 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.C'
_ choice A B := C // 36. should flag an error, Ambiguous assignment to ...
--------------------^
'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.C' is assignable to 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.A', 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.B'


--CURDIR--/choice_negative.fz:171:21: error 13: Ambiguous assignment to 'choice choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.A choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.B' from 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.C'
t choice A B => C // 37. should flag an error, Ambiguous assignment to ...
--------------------^
'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.C' is assignable to 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.A', 'choice_negative.this.ambiguous_assignment_to_choice_via_subtype.this.B'


--CURDIR--/choice_negative.fz:158:11: error 14: 'match' subject type must be a choice type
match 42 // 34. should flag an error, match subject must be choice
----------^^
Expand Down

0 comments on commit 7fec268

Please sign in to comment.