diff --git a/pkg/front_end/lib/src/kernel/body_builder.dart b/pkg/front_end/lib/src/kernel/body_builder.dart index 784fbe29aa35..963a977e8254 100644 --- a/pkg/front_end/lib/src/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/kernel/body_builder.dart @@ -3342,7 +3342,8 @@ class BodyBuilder extends StackListenerImpl (setterBuilder.isField || setterBuilder.isStatic)) { setterBuilder = null; } - if (declaration == null && setterBuilder == null) { + if ((declaration == null && setterBuilder == null) || + thisVariable == null) { return new UnresolvedNameGenerator( this, nameToken, new Name(name, libraryBuilder.nameOrigin), unresolvedReadKind: UnresolvedKind.Unknown); diff --git a/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart new file mode 100644 index 000000000000..045ca6cc5598 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart @@ -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. + +extension Foo on int { + bar(){} + bar baz; +} diff --git a/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.expect b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.expect new file mode 100644 index 000000000000..e50d2ddd0e64 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.expect @@ -0,0 +1,28 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:7: Error: Extensions can't declare instance fields +// Try removing the field declaration or making it a static field +// bar baz; +// ^^^ +// +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:3: Error: 'bar' isn't a type. +// bar baz; +// ^^^ +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:6:3: Context: This isn't a type. +// bar(){} +// ^^^ +// +import self as self; +import "dart:core" as core; + +extension Foo on core::int { + method bar = self::Foo|bar; + method tearoff bar = self::Foo|get#bar; + field baz = self::Foo|baz; +} +static field invalid-type Foo|baz; +static extension-member method Foo|bar(lowered final core::int #this) → dynamic {} +static extension-member method Foo|get#bar(lowered final core::int #this) → () → dynamic + return () → dynamic => self::Foo|bar(#this); diff --git a/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.modular.expect b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.modular.expect new file mode 100644 index 000000000000..e50d2ddd0e64 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.modular.expect @@ -0,0 +1,28 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:7: Error: Extensions can't declare instance fields +// Try removing the field declaration or making it a static field +// bar baz; +// ^^^ +// +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:3: Error: 'bar' isn't a type. +// bar baz; +// ^^^ +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:6:3: Context: This isn't a type. +// bar(){} +// ^^^ +// +import self as self; +import "dart:core" as core; + +extension Foo on core::int { + method bar = self::Foo|bar; + method tearoff bar = self::Foo|get#bar; + field baz = self::Foo|baz; +} +static field invalid-type Foo|baz; +static extension-member method Foo|bar(lowered final core::int #this) → dynamic {} +static extension-member method Foo|get#bar(lowered final core::int #this) → () → dynamic + return () → dynamic => self::Foo|bar(#this); diff --git a/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.outline.expect b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.outline.expect new file mode 100644 index 000000000000..3b8750f90542 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.outline.expect @@ -0,0 +1,29 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:7: Error: Extensions can't declare instance fields +// Try removing the field declaration or making it a static field +// bar baz; +// ^^^ +// +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:3: Error: 'bar' isn't a type. +// bar baz; +// ^^^ +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:6:3: Context: This isn't a type. +// bar(){} +// ^^^ +// +import self as self; +import "dart:core" as core; + +extension Foo on core::int { + method bar = self::Foo|bar; + method tearoff bar = self::Foo|get#bar; + field baz = self::Foo|baz; +} +static field invalid-type Foo|baz; +static extension-member method Foo|bar(lowered final core::int #this) → dynamic + ; +static extension-member method Foo|get#bar(lowered final core::int #this) → () → dynamic + return () → dynamic => self::Foo|bar(#this); diff --git a/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.transformed.expect b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.transformed.expect new file mode 100644 index 000000000000..e50d2ddd0e64 --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.strong.transformed.expect @@ -0,0 +1,28 @@ +library; +// +// Problems in library: +// +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:7: Error: Extensions can't declare instance fields +// Try removing the field declaration or making it a static field +// bar baz; +// ^^^ +// +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:3: Error: 'bar' isn't a type. +// bar baz; +// ^^^ +// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:6:3: Context: This isn't a type. +// bar(){} +// ^^^ +// +import self as self; +import "dart:core" as core; + +extension Foo on core::int { + method bar = self::Foo|bar; + method tearoff bar = self::Foo|get#bar; + field baz = self::Foo|baz; +} +static field invalid-type Foo|baz; +static extension-member method Foo|bar(lowered final core::int #this) → dynamic {} +static extension-member method Foo|get#bar(lowered final core::int #this) → () → dynamic + return () → dynamic => self::Foo|bar(#this); diff --git a/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.textual_outline.expect b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.textual_outline.expect new file mode 100644 index 000000000000..bd45fff0b86f --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.textual_outline.expect @@ -0,0 +1,4 @@ +extension Foo on int { + bar(){} + bar baz; +} diff --git a/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.textual_outline_modelled.expect b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.textual_outline_modelled.expect new file mode 100644 index 000000000000..bd45fff0b86f --- /dev/null +++ b/pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart.textual_outline_modelled.expect @@ -0,0 +1,4 @@ +extension Foo on int { + bar(){} + bar baz; +}