Skip to content

Commit dbc9c86

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] Fix crash in extension type declared instance field type pointing 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]>
1 parent bc07511 commit dbc9c86

8 files changed

+131
-1
lines changed

pkg/front_end/lib/src/kernel/body_builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3342,7 +3342,8 @@ class BodyBuilder extends StackListenerImpl
33423342
(setterBuilder.isField || setterBuilder.isStatic)) {
33433343
setterBuilder = null;
33443344
}
3345-
if (declaration == null && setterBuilder == null) {
3345+
if ((declaration == null && setterBuilder == null) ||
3346+
thisVariable == null) {
33463347
return new UnresolvedNameGenerator(
33473348
this, nameToken, new Name(name, libraryBuilder.nameOrigin),
33483349
unresolvedReadKind: UnresolvedKind.Unknown);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
extension Foo on int {
6+
bar(){}
7+
bar baz;
8+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:7: Error: Extensions can't declare instance fields
6+
// Try removing the field declaration or making it a static field
7+
// bar baz;
8+
// ^^^
9+
//
10+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:3: Error: 'bar' isn't a type.
11+
// bar baz;
12+
// ^^^
13+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:6:3: Context: This isn't a type.
14+
// bar(){}
15+
// ^^^
16+
//
17+
import self as self;
18+
import "dart:core" as core;
19+
20+
extension Foo on core::int {
21+
method bar = self::Foo|bar;
22+
method tearoff bar = self::Foo|get#bar;
23+
field baz = self::Foo|baz;
24+
}
25+
static field invalid-type Foo|baz;
26+
static extension-member method Foo|bar(lowered final core::int #this) → dynamic {}
27+
static extension-member method Foo|get#bar(lowered final core::int #this) → () → dynamic
28+
return () → dynamic => self::Foo|bar(#this);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:7: Error: Extensions can't declare instance fields
6+
// Try removing the field declaration or making it a static field
7+
// bar baz;
8+
// ^^^
9+
//
10+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:3: Error: 'bar' isn't a type.
11+
// bar baz;
12+
// ^^^
13+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:6:3: Context: This isn't a type.
14+
// bar(){}
15+
// ^^^
16+
//
17+
import self as self;
18+
import "dart:core" as core;
19+
20+
extension Foo on core::int {
21+
method bar = self::Foo|bar;
22+
method tearoff bar = self::Foo|get#bar;
23+
field baz = self::Foo|baz;
24+
}
25+
static field invalid-type Foo|baz;
26+
static extension-member method Foo|bar(lowered final core::int #this) → dynamic {}
27+
static extension-member method Foo|get#bar(lowered final core::int #this) → () → dynamic
28+
return () → dynamic => self::Foo|bar(#this);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:7: Error: Extensions can't declare instance fields
6+
// Try removing the field declaration or making it a static field
7+
// bar baz;
8+
// ^^^
9+
//
10+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:3: Error: 'bar' isn't a type.
11+
// bar baz;
12+
// ^^^
13+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:6:3: Context: This isn't a type.
14+
// bar(){}
15+
// ^^^
16+
//
17+
import self as self;
18+
import "dart:core" as core;
19+
20+
extension Foo on core::int {
21+
method bar = self::Foo|bar;
22+
method tearoff bar = self::Foo|get#bar;
23+
field baz = self::Foo|baz;
24+
}
25+
static field invalid-type Foo|baz;
26+
static extension-member method Foo|bar(lowered final core::int #this) → dynamic
27+
;
28+
static extension-member method Foo|get#bar(lowered final core::int #this) → () → dynamic
29+
return () → dynamic => self::Foo|bar(#this);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:7: Error: Extensions can't declare instance fields
6+
// Try removing the field declaration or making it a static field
7+
// bar baz;
8+
// ^^^
9+
//
10+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:7:3: Error: 'bar' isn't a type.
11+
// bar baz;
12+
// ^^^
13+
// pkg/front_end/testcases/regress/extension_type_field_has_method_type.dart:6:3: Context: This isn't a type.
14+
// bar(){}
15+
// ^^^
16+
//
17+
import self as self;
18+
import "dart:core" as core;
19+
20+
extension Foo on core::int {
21+
method bar = self::Foo|bar;
22+
method tearoff bar = self::Foo|get#bar;
23+
field baz = self::Foo|baz;
24+
}
25+
static field invalid-type Foo|baz;
26+
static extension-member method Foo|bar(lowered final core::int #this) → dynamic {}
27+
static extension-member method Foo|get#bar(lowered final core::int #this) → () → dynamic
28+
return () → dynamic => self::Foo|bar(#this);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extension Foo on int {
2+
bar(){}
3+
bar baz;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extension Foo on int {
2+
bar(){}
3+
bar baz;
4+
}

0 commit comments

Comments
 (0)