Skip to content

Fasta: Missing override checks for mixins #34235

Closed
@stereotype441

Description

@stereotype441

Consider the following program:

class Base {
  void foo() {
    print('Base.foo called');
  }
}
class M1 {
  void foo({x}) {
    print('M1.foo called, with x=$x');
  }
}
class BaseWithM1 = Base with M1;
class M2 {
  void foo() {
    print('M2.foo called');
  }
}
class Derived extends BaseWithM1 with M2 {}
main() {
  new Derived().foo();
}

I'm not certain what the behavior of this program should be, but I think it should be either:

  • Undefined due to an error (since the mixin application BaseWithM1 with M2 attempts to override foo({x}) with foo(), and overrides may not drop optional parameters.
  • Prints M2.foo called.

If I run this under the VM, it reports no errors and prints M1.foo called, with x=null. That seems definitely wrong. So even though I'm not certain what the correct behavior should be I'm filing this as a VM bug. Feel free to reclassify if I'm wrong about this.

Note that this is a reduction of a situation arose in practice during development of the analyzer/front_end integration. The actual classes/methods involved were:

  • Base -> Generator
  • M1 -> KernelExpressionGenerator
  • BaseWithM1 -> KernelGenerator
  • M2 -> ContextAwareGenerator
  • Derived -> KernelContextAwareGenerator
  • foo -> buildCompoundAssignment

I'll shortly upload a CL that modifies the parameters of buildCompoundAssignment to work around this issue.

Cc @leafpetersen, @eernstg, and @lrhn to weigh in on what the correct behavior should be.

Metadata

Metadata

Labels

P2A bug or feature request we're likely to work onfront-end-missing-errorlegacy-area-front-endLegacy: Use area-dart-model instead.soundnesstype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions