Skip to content

Conversation

@Kamirus
Copy link
Contributor

@Kamirus Kamirus commented Oct 24, 2025

Fix the M0223 warning check for redundant type instantiations to avoid false positives.
This check is now correctly performed during not env.pre phase like all other warnings.
Also: Correctly handles nested expressions, further avoiding false positives.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2025

Comparing from e38045b to 8778f70:
The produced WebAssembly code seems to be completely unchanged.
In terms of gas, no changes are observed in 5 tests.
In terms of size, no changes are observed in 5 tests.

@Kamirus Kamirus marked this pull request as ready for review October 27, 2025 12:15
@Kamirus Kamirus requested a review from a team as a code owner October 27, 2025 12:15
let closed_codom = Bi_match.is_closed remaining codom in
(* Closed [codom] implies closed [body_typ]. [body_typ] is closed when it comes from [typ_opt] *)
let closed_body_typ = closed_codom || Option.is_some typ_opt in
let env' = if closed_body_typ then env' else { env' with rets = None } in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if env'.rets = None, that means the body can't return at all which is weird because functions can always return. There's only a few places where we disallow returns (e.g. object/class constructors) so maybe we should discuss.
Are you ever checking the body of a function with env'.rets = None? If not, probably ok.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think you are at line 2989

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point. It's better to distinguish between None and Some here for rets
It should be more like type rets = NotAllowed | RetBimatch | Ret typ.
And a custom error when trying to check when RetBimatch saying that cannot infer type of return etc.

Copy link
Contributor

@crusso crusso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly thought, and I haven't thought it through, but I wonder if one could get away with only updating the notes once, when they contain T.Pre (or a PreLit), and just not apply any further update.

@Kamirus Kamirus changed the title fix: Redundant type instantiation wrong when return expression fix: Inference and Redundant type instantiation wrong when return expression Oct 28, 2025
@Kamirus
Copy link
Contributor Author

Kamirus commented Oct 28, 2025

Silly thought, and I haven't thought it through, but I wonder if one could get away with only updating the notes once, when they contain T.Pre (or a PreLit), and just not apply any further update.

We need to perform the redundancy check before check_exp, otherwise the modifications to the state during check_exp would affect the result of the redundancy check.
So we need to perform the redundancy check first, avoid making state changes (so they would not affect the 2nd check) and make the final committing check.

@Kamirus Kamirus requested a review from crusso October 28, 2025 11:00
check_exp_strong env t exp1
| None ->
| BimatchRet k ->
k env exp1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will actually wind up doing infer_exp rather than check_exp_strong (as on 2084). God knows if that would make a difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing infer is expected, but true I can pass the weak = false here
Continuation in a separate PR here #5615

@Kamirus Kamirus changed the title fix: Inference and Redundant type instantiation wrong when return expression fix: Redundant type instantiation wrong when return expression Oct 28, 2025
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.

2 participants