Skip to content

Commit

Permalink
[CFE] Fix crash in extension type declared instance field type pointi…
Browse files Browse the repository at this point in the history
…ng to method

Change-Id: I6d1d34f487d0095c306c3144e61cca7bd4bc559d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397920
Commit-Queue: Jens Johansen <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
  • Loading branch information
jensjoha authored and Commit Queue committed Nov 28, 2024
1 parent bc07511 commit dbc9c86
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/front_end/lib/src/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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.

extension Foo on int {
bar(){}
bar baz;
}
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extension Foo on int {
bar(){}
bar baz;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extension Foo on int {
bar(){}
bar baz;
}

0 comments on commit dbc9c86

Please sign in to comment.