Skip to content

Commit

Permalink
[CFE] Fix crash on abstracty field with duplicate initializer
Browse files Browse the repository at this point in the history
Change-Id: I8b33ab973ad0849c36ccec6b6136d53f1b1b2cd0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397761
Commit-Queue: Jens Johansen <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
  • Loading branch information
jensjoha authored and Commit Queue committed Nov 27, 2024
1 parent 18f43cf commit b77865d
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/front_end/lib/src/source/source_field_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,8 @@ class AbstractOrExternalFieldEncoding implements FieldEncoding {
@override
Initializer buildErroneousInitializer(Expression effect, Expression value,
{required int fileOffset}) {
throw new UnsupportedError("$runtimeType.buildDuplicatedInitializer");
return new ShadowInvalidFieldInitializer(type, value, effect)
..fileOffset = fileOffset;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

abstract class Foo {
abstract int foo;
Foo(this.foo, this.foo) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:22: Error: Duplicated parameter name 'foo'.
// Foo(this.foo, this.foo) {}
// ^^^
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:12: Context: Other parameter named 'foo'.
// Foo(this.foo, this.foo) {}
// ^^^
//
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:12: Error: Abstract fields cannot have initializers.
// Try removing the field initializer or the 'abstract' keyword from the field declaration.
// Foo(this.foo, this.foo) {}
// ^^^
//
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:22: Error: 'foo' was already initialized by this constructor.
// Foo(this.foo, this.foo) {}
// ^
//
import self as self;
import "dart:core" as core;

abstract class Foo extends core::Object {
constructor •(core::int foo, core::int foo) → self::Foo
: final dynamic #t1 = invalid-expression "pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:12: Error: Abstract fields cannot have initializers.
Try removing the field initializer or the 'abstract' keyword from the field declaration.
Foo(this.foo, this.foo) {}
^^^", final dynamic #t2 = invalid-expression "pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:22: Error: 'foo' was already initialized by this constructor.
Foo(this.foo, this.foo) {}
^" {}
abstract get foo() → core::int;
abstract set foo(synthesized core::int #externalFieldValue) → void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:22: Error: Duplicated parameter name 'foo'.
// Foo(this.foo, this.foo) {}
// ^^^
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:12: Context: Other parameter named 'foo'.
// Foo(this.foo, this.foo) {}
// ^^^
//
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:12: Error: Abstract fields cannot have initializers.
// Try removing the field initializer or the 'abstract' keyword from the field declaration.
// Foo(this.foo, this.foo) {}
// ^^^
//
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:22: Error: 'foo' was already initialized by this constructor.
// Foo(this.foo, this.foo) {}
// ^
//
import self as self;
import "dart:core" as core;

abstract class Foo extends core::Object {
constructor •(core::int foo, core::int foo) → self::Foo
: final dynamic #t1 = invalid-expression "pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:12: Error: Abstract fields cannot have initializers.
Try removing the field initializer or the 'abstract' keyword from the field declaration.
Foo(this.foo, this.foo) {}
^^^", final dynamic #t2 = invalid-expression "pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:22: Error: 'foo' was already initialized by this constructor.
Foo(this.foo, this.foo) {}
^" {}
abstract get foo() → core::int;
abstract set foo(synthesized core::int #externalFieldValue) → void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:22: Error: Duplicated parameter name 'foo'.
// Foo(this.foo, this.foo) {}
// ^^^
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:12: Context: Other parameter named 'foo'.
// Foo(this.foo, this.foo) {}
// ^^^
//
import self as self;
import "dart:core" as core;

abstract class Foo extends core::Object {
constructor •(core::int foo, core::int foo) → self::Foo
;
abstract get foo() → core::int;
abstract set foo(synthesized core::int #externalFieldValue) → void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:22: Error: Duplicated parameter name 'foo'.
// Foo(this.foo, this.foo) {}
// ^^^
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:12: Context: Other parameter named 'foo'.
// Foo(this.foo, this.foo) {}
// ^^^
//
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:12: Error: Abstract fields cannot have initializers.
// Try removing the field initializer or the 'abstract' keyword from the field declaration.
// Foo(this.foo, this.foo) {}
// ^^^
//
// pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:22: Error: 'foo' was already initialized by this constructor.
// Foo(this.foo, this.foo) {}
// ^
//
import self as self;
import "dart:core" as core;

abstract class Foo extends core::Object {
constructor •(core::int foo, core::int foo) → self::Foo
: final dynamic #t1 = invalid-expression "pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:12: Error: Abstract fields cannot have initializers.
Try removing the field initializer or the 'abstract' keyword from the field declaration.
Foo(this.foo, this.foo) {}
^^^", final dynamic #t2 = invalid-expression "pkg/front_end/testcases/regress/abstract_field_duplicate_initializer.dart:7:22: Error: 'foo' was already initialized by this constructor.
Foo(this.foo, this.foo) {}
^" {}
abstract get foo() → core::int;
abstract set foo(synthesized core::int #externalFieldValue) → void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
abstract class Foo {
abstract int foo;
Foo(this.foo, this.foo) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
abstract class Foo {
Foo(this.foo, this.foo) {}
abstract int foo;
}

0 comments on commit b77865d

Please sign in to comment.