Skip to content

Commit b36734f

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
Fix crash when duplicate fields have annotations
Fixes #36793. Change-Id: I007699978219dc642e23951ab78858504a192c03 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/100646 Reviewed-by: Kevin Millikin <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 30e21f3 commit b36734f

8 files changed

+112
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,9 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
601601
buildDartType(pop()); // Type.
602602
}
603603
List<Expression> annotations = pop();
604-
if (annotations != null) {
604+
// Fields with duplicate names are sorted out in the else branch of the
605+
// `declaration.next == null` above.
606+
if (annotations != null && fields.isNotEmpty) {
605607
inferAnnotations(annotations);
606608
Field field = fields.first.target;
607609
// The first (and often only field) will not get a clone.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2019, 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+
const int y = 42;
6+
7+
@y
8+
int x = 1;
9+
@y
10+
int x = 2;
11+
12+
main() {
13+
print(y);
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/issue_36793.dart:10:5: Error: 'x' is already declared in this scope.
6+
// int x = 2;
7+
// ^
8+
// pkg/front_end/testcases/regress/issue_36793.dart:8:5: Context: Previous declaration of 'x'.
9+
// int x = 1;
10+
// ^
11+
//
12+
import self as self;
13+
import "dart:core" as core;
14+
15+
static const field core::int y = 42;
16+
static field core::int x;
17+
static method main() → dynamic {
18+
core::print(self::y);
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/issue_36793.dart:10:5: Error: 'x' is already declared in this scope.
6+
// int x = 2;
7+
// ^
8+
// pkg/front_end/testcases/regress/issue_36793.dart:8:5: Context: Previous declaration of 'x'.
9+
// int x = 1;
10+
// ^
11+
//
12+
import self as self;
13+
import "dart:core" as core;
14+
15+
static const field core::int y = 42;
16+
static field core::int x;
17+
static method main() → dynamic {
18+
core::print(self::y);
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/issue_36793.dart:10:5: Error: 'x' is already declared in this scope.
6+
// int x = 2;
7+
// ^
8+
// pkg/front_end/testcases/regress/issue_36793.dart:8:5: Context: Previous declaration of 'x'.
9+
// int x = 1;
10+
// ^
11+
//
12+
import self as self;
13+
import "dart:core" as core;
14+
15+
static const field core::int y;
16+
static field core::int x;
17+
static method main() → dynamic
18+
;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/issue_36793.dart:10:5: Error: 'x' is already declared in this scope.
6+
// int x = 2;
7+
// ^
8+
// pkg/front_end/testcases/regress/issue_36793.dart:8:5: Context: Previous declaration of 'x'.
9+
// int x = 1;
10+
// ^
11+
//
12+
import self as self;
13+
import "dart:core" as core;
14+
15+
static const field core::int y = 42;
16+
static field core::int x;
17+
static method main() → dynamic {
18+
core::print(self::y);
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/issue_36793.dart:10:5: Error: 'x' is already declared in this scope.
6+
// int x = 2;
7+
// ^
8+
// pkg/front_end/testcases/regress/issue_36793.dart:8:5: Context: Previous declaration of 'x'.
9+
// int x = 1;
10+
// ^
11+
//
12+
import self as self;
13+
import "dart:core" as core;
14+
15+
static const field core::int y = 42;
16+
static field core::int x;
17+
static method main() → dynamic {
18+
core::print(self::y);
19+
}

pkg/front_end/testcases/text_serialization.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ regress/issue_35900: TextSerializationFailure
922922
regress/issue_36400: TextSerializationFailure
923923
regress/issue_36647: TextSerializationFailure
924924
regress/issue_36647_2: TextSerializationFailure
925+
regress/issue_36793: TextSerializationFailure
925926
reject_generic_function_types_in_bounds: TextSerializationFailure # Was: RuntimeError # Expected
926927
return_with_unknown_type_in_context: TextSerializationFailure # Was: Pass
927928
runtime_checks/call_kinds: TextSerializationFailure # Was: Pass

0 commit comments

Comments
 (0)