Skip to content

Conversation

@lihaoyi
Copy link
Contributor

@lihaoyi lihaoyi commented Jan 14, 2026

Attempts to fix #23932. Vibe coded

Problem

Extension methods with erased parameters could incorrectly be counted as implementations of non-extension abstract methods, because when erased parameters are filtered out during signature matching, the signatures could appear to match.

Fix

In compiler/src/dotty/tools/dotc/typer/RefChecks.scala, I added a check to the isImplemented function:

&& !(impl.symbol.is(ExtensionMethod) && !mbr.is(ExtensionMethod))

This ensures:

  • Extension methods cannot implement non-extension abstract methods (the bug)
  • Extension methods can implement abstract extension methods (legitimate use case like type classes)

Test File

Created tests/neg/i23932.scala with 9 test cases:

  • Cases 1-6 (errors): Extension methods incorrectly trying to implement non-extension abstract methods
  • Cases 7-9 (OK): Extension methods properly implementing abstract extension methods

Verification

  • The test file produces exactly 5 expected errors
  • Existing extension tests (tests/run/extension-methods.scala, tests/neg/extension-methods.scala, tests/neg/override-extension_normal-methods.scala) continue to work correctly
  • The fix is consistent with existing behavior where normal methods cannot override extension methods and vice versa

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

The problem is, if the signature matches then the extension method does in fact override the abstract method by the JVM semantics. So the test cannot be simply dropped; we risk getting a wrong override instead.

@odersky odersky removed their assignment Jan 16, 2026
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.

No check for abstract methods when Erased instances are around

2 participants