Skip to content

Conversation

@Kamirus
Copy link
Contributor

@Kamirus Kamirus commented Dec 10, 2025

What?
Makes 'inconsistent type' warnings as errors by default (minor breaking change, fixable by -W moc flag):

"M0061", "Comparing abstract type to itself at supertype";
"M0062", "Comparing incompatible type at common supertype";
"M0074", "Array elements have inconsistent types";
"M0081", "If branches have inconsistent types";
"M0101", "Switch with inconsistent branch types";
"M0166", "Type intersection results in abstract type";
"M0167", "Type union results in bottom type";
"M0190", "Types inconsistent for alternative pattern variables, losing information";

Why?
Caffeine needs to treat these as errors. However, it makes sense now (since we have a way to modify the lint level) to actually treat them as errors by default. IMO all of the above messages are type errors that signal a bug in the code

To avoid breaking change without modifying the code pass the following flag to moc
-W M0061,M0062,M0074,M0081,M0101,M0166,M0167,M0190

"M0237", None, "Suggest redundant explicit arguments";
"M0239", None, "Avoid binding a unit `()` result";
"M0005", None, "Case mismatch between import and filename", Warn;
"M0061", None, "Comparing abstract type to itself at supertype", Error;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the list of warnings that I'd treat as errors by default

"M0061", "Comparing abstract type to itself at supertype";
"M0062", "Comparing incompatible type at common supertype";
"M0074", "Array elements have inconsistent types";
"M0081", "If branches have inconsistent types";
"M0101", "Switch with inconsistent branch types";
"M0166", "Type intersection results in abstract type";
"M0167", "Type union results in bottom type";
"M0190", "Types inconsistent for alternative pattern variables, losing information";

@Kamirus Kamirus changed the title experiment: treat 'inconsistent types' warnings as errors by default feat: treat 'inconsistent types' warnings as errors by default Dec 10, 2025
@Kamirus Kamirus changed the title feat: treat 'inconsistent types' warnings as errors by default feat: 'inconsistent types' warnings as errors by default Dec 10, 2025
@Kamirus Kamirus marked this pull request as ready for review December 10, 2025 13:27
@Kamirus Kamirus requested a review from a team as a code owner December 10, 2025 13:27
@github-actions
Copy link
Contributor

github-actions bot commented Dec 10, 2025

Comparing from 5198962 to cf446a4:
In terms of gas, no changes are observed in 5 tests.
In terms of size, no changes are observed in 5 tests.

@crusso
Copy link
Contributor

crusso commented Dec 12, 2025

I dunno, seems a bit odd to rule out something that doesn't actually go wrong.

Doesn't caffeine compile with warnings as errors anyway?

@Kamirus
Copy link
Contributor Author

Kamirus commented Dec 15, 2025

Doesn't caffeine compile with warnings as errors anyway?

Not every warning, no. They would need to switch all these flags.

I dunno, seems a bit odd to rule out something that doesn't actually go wrong.

  1. It delays errors, typechecks as Any in one place, raises an error later.
  2. Leads to bugs when Any is later compared using ==, does not go wrong typing-wise, but very wrong at runtime
  3. We cannot use Any in any meaningful way, we have no downcasting. I'd treat resolving Any as the best common type (LUB) as error (it would help with bimatch errors too, but that is a separate story, not this PR), and only allow it with an explicit annotation : Any (in check_typ path)

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.

3 participants