Skip to content

Mark Conditional.execute overrides as @protected - #720

Open
Shubham-Padkonde wants to merge 1 commit into
intel:mainfrom
Shubham-Padkonde:protected-conditional-execute
Open

Shubham-Padkonde wants to merge 1 commit into
intel:mainfrom
Shubham-Padkonde:protected-conditional-execute

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

Description & Motivation

Conditional.execute is already annotated @protected on the base class, but Dart does not propagate that annotation to overrides — each override has to carry it itself. All four Conditional subclasses declared only @override, so the restriction quietly disappeared whenever the caller's static type was the subclass rather than Conditional.

Concretely, on main this code produces no analyzer complaint:

final cond = If(Logic(), then: [Logic() < 1]);
cond.execute(null, null);

final assign = ConditionalAssign(Logic(), Logic());
assign.execute(null, null);

With this change, both calls are flagged:

warning - probe.dart:6:8 - The member 'execute' can only be used within instance members of subclasses of 'If'. - invalid_use_of_protected_member
warning - probe.dart:9:10 - The member 'execute' can only be used within instance members of subclasses of 'ConditionalAssign'. - invalid_use_of_protected_member

Same file analyzed either way: 4 issues without the change, 6 with it — the two new ones being exactly the calls above.

This covers all four subclasses of Conditional (Case, ConditionalAssign, ConditionalGroup, If); I checked for others with grep -rn "extends Conditional\b" lib/src and there are no more.

Related Issue(s)

Fixes #596

Testing

The change is annotation-only, so the analyzer is the real check here.

dart analyze over the whole package is clean:

Analyzing rohd...
No issues found!

That matters because the legitimate internal callers in Combinational and Sequential already carry // ignore: invalid_use_of_protected_member comments — tightening the overrides did not turn any of them into a new warning, and did not require adding any new ignores.

dart format --output=none --set-exit-if-changed reports no changes.

Tests still behave as before — conditionals_test.dart, fsm_test.dart, comb_math_test.dart and comb_mod_test.dart give +31 -25, where all 25 failures are ProcessException ... Command: iverilog -g2012 ... because Icarus Verilog is not installed on my machine, which CONTRIBUTING notes is required for the complete suite. CI has it.

Backwards-compatibility

Not a breaking change for the simulator or generated output — annotations have no runtime effect.

It is a new analyzer warning for any downstream code that was calling execute on a concrete Conditional subclass from outside, which is precisely the misuse #596 asks to surface. Such code was already getting the warning when it went through a Conditional-typed reference, so this makes the existing rule consistent rather than introducing a new one.

Documentation

No documentation changes needed — the base class doc comment on execute already describes it as being called by Always execution, and this just makes the annotations match that.


Disclosure: this change was written by Claude Code (Claude Opus 5) working as my agent, at my direction. The analyzer output quoted above comes from real runs in my local environment; I am accountable for the content of this PR and happy to iterate on review feedback.

🤖 Generated with Claude Code

Conditional.execute is declared @Protected on the base class, but Dart
does not propagate the annotation to overrides: each override has to
carry it. All four Conditional subclasses -- Case, ConditionalAssign,
ConditionalGroup and If -- declared only @OverRide, so a call made
through the subclass type was not flagged, even though the same call
through a Conditional-typed reference was.

Add @Protected to the four overrides so the restriction holds no matter
which static type the caller uses.

Fixes intel#596

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add @protected onto execute on Conditionals

1 participant