Files
sdk/pkg/front_end/testcases/general/many_errors.dart.strong.expect
T
Johnni Winther 4cfd3da965 [cfe][PrimaryConstructors] Update reporting for mixin class with initializer/constructor body
This update the position used for reporting a mixin class primary constructor with a primary constructor by declaration with initializers or an explicit body. Since mixin classes can have simple constructors, it makes more sense to report the error on the offending syntax than on the primary constructor itself.

The CL also updates the offset used for field initializers to the field name rather than the `=`. This align the offset with what is used for property sets.

Change-Id: Id5ccd55536b2c3b9d9336d2854772c1bcc5a175a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490800
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-04-01 01:17:28 -07:00

103 lines
4.4 KiB
Plaintext

library;
//
// Problems in library:
//
// pkg/front_end/testcases/general/many_errors.dart:8:3: Error: A const constructor can't have a body.
// Try removing either the 'const' keyword or the body.
// const A.named1() sync* {}
// ^^^^^
//
// pkg/front_end/testcases/general/many_errors.dart:15:1: Error: An external or native method can't have a body.
// external foo(String x) {
// ^^^^^^^^
//
// pkg/front_end/testcases/general/many_errors.dart:10:26: Error: New expression is not a constant expression.
// const A.named2() : x = new Object();
// ^^^
//
// pkg/front_end/testcases/general/many_errors.dart:10:22: Error: 'x' is a final instance variable that was initialized at the declaration.
// const A.named2() : x = new Object();
// ^
// pkg/front_end/testcases/general/many_errors.dart:6:9: Context: 'x' was initialized here.
// final x = null;
// ^
//
// pkg/front_end/testcases/general/many_errors.dart:12:22: Error: 'x' is a final instance variable that was initialized at the declaration.
// const A.named3() : x = const Object();
// ^
// pkg/front_end/testcases/general/many_errors.dart:6:9: Context: 'x' was initialized here.
// final x = null;
// ^
//
// pkg/front_end/testcases/general/many_errors.dart:8:26: Error: Constructor bodies can't use 'async', 'async*', or 'sync*'.
// const A.named1() sync* {}
// ^
//
// pkg/front_end/testcases/general/many_errors.dart:15:24: Error: An external or native method can't have a body.
// external foo(String x) {
// ^
//
// pkg/front_end/testcases/general/many_errors.dart:30:9: Error: The class 'AbstractClass' is abstract and can't be instantiated.
// const AbstractClass.id();
// ^^^^^^^^^^^^^
//
// pkg/front_end/testcases/general/many_errors.dart:31:27: Error: The getter 'b' isn't defined for the type 'B'.
// - 'B' is from 'pkg/front_end/testcases/general/many_errors.dart'.
// Try correcting the name to the name of an existing getter, or defining a getter or field named 'b'.
// (new C().b ??= new B()).b;
// ^
//
import self as self;
import "dart:core" as core;
class A extends core::Object /*hasConstConstructor*/ {
final field dynamic x = null;
constructor named1() → self::A
: invalid-initializer "pkg/front_end/testcases/general/many_errors.dart:8:26: Error: Constructor bodies can't use 'async', 'async*', or 'sync*'.
const A.named1() sync* {}
^" {}
const constructor named2() → self::A
: invalid-initializer "pkg/front_end/testcases/general/many_errors.dart:10:22: Error: 'x' is a final instance variable that was initialized at the declaration.
const A.named2() : x = new Object();
^"
;
const constructor named3() → self::A
: invalid-initializer "pkg/front_end/testcases/general/many_errors.dart:12:22: Error: 'x' is a final instance variable that was initialized at the declaration.
const A.named3() : x = const Object();
^"
;
}
class B extends core::Object {
synthetic constructor •() → self::B
: super core::Object::•()
;
}
class C extends core::Object {
late field self::B b;
synthetic constructor •() → self::C
: super core::Object::•()
;
}
abstract class AbstractClass extends core::Object /*hasConstConstructor*/ {
const constructor id() → self::AbstractClass
: super core::Object::•()
;
}
external static method foo(core::String x) → dynamic {
invalid-expression "pkg/front_end/testcases/general/many_errors.dart:15:24: Error: An external or native method can't have a body.
external foo(String x) {
^";
{
return x.{core::String::length}{core::int};
}
}
static method m() → dynamic {
invalid-expression "The class 'AbstractClass' is abstract and can't be instantiated.";
invalid-expression "pkg/front_end/testcases/general/many_errors.dart:31:27: Error: The getter 'b' isn't defined for the type 'B'.
- 'B' is from 'pkg/front_end/testcases/general/many_errors.dart'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'b'.
(new C().b ??= new B()).b;
^" in (let final self::C #t1 = new self::C::•() in let final self::B #t2 = #t1.{self::C::b}{self::B} in #t2 == null ?{self::B} #t1.{self::C::b} = new self::B::•() : #t2){<unresolved>}.b;
}
static method main() → dynamic {}