Skip to content

CFE makes impossible suggestion to user when rejecting code due to incompatible signatures in desugared mixin application #61158

@stereotype441

Description

@stereotype441

(Split out from #61145)

Given the following code:

void main() {}

abstract class A {}

abstract class B {}

mixin C {}

abstract class D {
  F get foo;
}

abstract class F {}

abstract class G implements D {}

abstract class H implements F {}

abstract class I implements D, A {
  @override
  J get foo;
}

abstract class J implements F, A {}

abstract class K<E extends F> {
  E get foo;
}

abstract class L implements G, A {}

abstract class M implements H, A {}

mixin N<E extends H> implements K<E> {}

abstract class O implements I {
  @override
  P get foo;
}

abstract class P implements J {}

abstract class Q extends G implements I {}

mixin R on H {}

abstract class S implements O {
  @override
  T get foo;
}

abstract class T implements P {}

mixin U<E extends H> implements N<E> {}

mixin V<E extends H> implements N<E> {}

abstract class W extends Q implements O {}

abstract class X extends H with R {}

abstract class Y implements S {
  @override
  Z get foo;
}

abstract class Z implements T {}

mixin AA implements S {}

mixin BB on H implements X, M, J {}

abstract class CC extends W with AA, C implements L {
  @override
  DD get foo;
}

abstract class DD extends X with C, BB implements T {}

mixin EE on AA implements Y {}

class FF extends DD implements Z {}

mixin GG<E extends DD> implements N<E> {}

class HH extends CC with EE, GG<FF>, V<FF>, U<FF>, N<FF> implements B {
  @override
  final FF foo = throw '';
}

The CFE produces the error message:

pkg/analyzer/lib/repro.dart:86:7: Error: Class 'CC with EE' inherits multiple members named 'CC.foo%D.foo%I.foo%D.foo%O.foo%I.foo%D.foo%S.foo%O.foo%I.foo%D.foo%D.foo' with incompatible signatures.
Try adding a declaration of 'CC.foo%D.foo%I.foo%D.foo%O.foo%I.foo%D.foo%S.foo%O.foo%I.foo%D.foo%D.foo' to 'CC with EE'.
class HH extends CC with EE, GG<FF>, V<FF>, U<FF>, N<FF> implements B {
      ^
pkg/analyzer/lib/repro.dart:75:10: Context: This is one of the overridden members.
  DD get foo;
         ^^^
pkg/analyzer/lib/repro.dart:49:9: Context: This is one of the overridden members.
  T get foo;
        ^^^

But the suggestion "Try adding a declaration of 'CC.foo%D.foo%I.foo%D.foo%O.foo%I.foo%D.foo%S.foo%O.foo%I.foo%D.foo%D.foo' to 'CC with EE'." is impossible because:

  • CC with EE is not explicitly declared anywhere in the code. It's an unnamed mixin application that the CFE creates as part of desugaring the declaration of the class HH.
  • Even if CC with EE were changed to a named mixin application (by manually desugaring the declaration of HH so that the mixin applications were explicit), it would still be impossible, because declarations cannot be added to mixin applications.

Since the suggestion "Try adding a declaration..." is impossible, it should not be emitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-messagesPoor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions