Skip to content

Commit

Permalink
Adjusted Dart.g to contain the grammar updates of language repo PR 293
Browse files Browse the repository at this point in the history
This CL makes several adjustments to the spec_parser grammar Dart.g,
such that the spec_parser can parse the proposed NNBD constructs,
cf. language PR #293.

Change-Id: Ieec00259d73b6037d6a87d5c97cfac40186baef0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101500
Reviewed-by: Leaf Petersen <[email protected]>
Commit-Queue: Erik Ernst <[email protected]>
  • Loading branch information
eernstg authored and [email protected] committed Aug 14, 2019
1 parent 76c99bc commit a580529
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 57 deletions.
2 changes: 1 addition & 1 deletion tests/language_2/abstract_syntax_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ main() {

class A {
foo(); // //# 00: compile-time error
static bar(); // //# 01: compile-time error
static bar(); // //# 01: syntax error
}

class B extends A {
Expand Down
2 changes: 1 addition & 1 deletion tests/language_2/bad_constructor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// A constructor can't be static.
class A {
static //# 00: compile-time error
static //# 00: syntax error
A();
}

Expand Down
5 changes: 3 additions & 2 deletions tests/language_2/language_2_spec_parser.status
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const_native_factory_test: Skip # Uses `native`.
deep_nesting_expression_test: Skip # JVM stack overflow.
deep_nesting_statement_test: Skip # JVM stack overflow.
double_invalid_test: Skip # Contains illegaly formatted double.
extension_methods: Skip # Not yet supported.
external_test/21: Fail # Test expects `runtime error`, it is a syntax error.
getter_declaration_negative_test: Fail # Negative, uses getter with parameter.
inst_field_initializer1_negative_test: Skip # Negative, not syntax.
Expand All @@ -34,7 +35,8 @@ map_literal_negative_test: Fail # Negative, uses `new Map<int>{..}`.
new_expression1_negative_test: Fail # Negative, uses `new id`.
new_expression2_negative_test: Fail # Negative, uses `new id(`.
new_expression3_negative_test: Fail # Negative, uses `new id(...`.
nnbd/*: Skip # Not yet included.
nnbd/syntax/opt_out_nnbd_modifiers_test: Skip # Requires opt-out of NNBD.
nnbd/syntax/pre_nnbd_modifiers_test: Skip # Requires opt-out of NNBD.
no_such_method_negative_test: Skip # Negative, not syntax.
non_const_super_negative_test: Skip # Negative, not syntax.
operator1_negative_test: Fail # Negative, declares static operator.
Expand Down Expand Up @@ -65,4 +67,3 @@ test_negative_test: Fail # Negative, uses non-terminated string literal.
unary_plus_negative_test: Fail # Negative, uses non-existing unary plus.
vm/debug_break_enabled_vm_test/01: Fail # Uses debug break.
vm/debug_break_enabled_vm_test/none: Fail # Uses debug break.
void/void_type_function_types_test: Skip # Not yet supported.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ void main() {

class C {
var x = this; //# 00: compile-time error
late x = this; //# 01: ok
late var x = this; //# 01: ok
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void nullUses() async {
_null + 4; //# 165: compile-time error
-_null; //# 169: compile-time error
_null++; //# 170: compile-time error
++null; //# 171: compile-time error
++_null; //# 171: compile-time error
_null..isEven; //# 172: compile-time error
_null[3]; //# 170: compile-time error
_null[3] = 0; //# 171: compile-time error
Expand Down
80 changes: 80 additions & 0 deletions tests/language_2/nnbd/syntax/class_member_declarations_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) 2019, 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.

// SharedOptions=--enable-experiment=non-nullable

class A {
static late x1; //# 01: syntax error
static late final x2;
static late int x3;
static late final A x4;
static late x5 = 0; //# 02: syntax error
static late final x6 = 0;
static late int x7 = 0;
static late final A? x8 = null;

static final late x9; //# 03: syntax error
static final late A x10; //# 04: syntax error
static final late x11 = 0; //# 05: syntax error
static final late A x12 = null; //# 06: syntax error

covariant late var x13;
covariant late var x14 = '';
covariant late x15; //# 07: syntax error
covariant late x16 = ''; //# 08: syntax error

late covariant var x17; //# 09: syntax error
late covariant var x18 = ''; //# 10: syntax error
late covariant x19; //# 11: syntax error
late covariant x20 = ''; //# 12: syntax error

covariant var late x21; //# 13: syntax error
covariant var late x22 = ''; //# 14: syntax error

covariant late double x23;
covariant late String x24 = '';

covariant double late x23; //# 15: syntax error
covariant String late x24 = ''; //# 16: syntax error

late x25; //# 17: syntax error
late final x26;
late int x27;
late final A x28;
late x29 = 0; //# 18: syntax error
late final x30 = 0;
late int x31 = 0;
late final A? x32 = null;

final late x33; //# 19: syntax error
int late x34; //# 20: syntax error
var late x35; //# 21: syntax error
final late A x36; //# 22: syntax error
final late x37 = 0; //# 23: syntax error
int late x38 = 0; //# 24: syntax error
var late x39 = 0; //# 25: syntax error
final late A? x40 = null; //# 26: syntax error

List foo() {
final x41 = true;
late final x42;
late final x43 = [], x44 = {};
return x43;
}
}

abstract class B {
m1(int some, regular, covariant parameters, {
required p1,
// required p2 = null, // Likely intended to be an error.
required covariant p3,
required covariant int p4,
});
}

main() {
A? a;
String? s = '';
a?..foo().length..x27 = s!..toString().length;
}
6 changes: 3 additions & 3 deletions tests/language_2/nnbd/syntax/late_modifier_error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

// Invalid uses of "late" modifier

late //# 01: compile-time error
late //# 01: syntax error
int f1(
late //# 02: compile-time error
int x
) {}

late //# 03: compile-time error
late //# 03: syntax error
class C1 {
late //# 04: compile-time error
late //# 04: syntax error
int m() {}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/language_2/nnbd/syntax/non_null_assertion_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ main() {
});

int i = 0;
var x13 = [i++!]; // ignore: unnecessary_non_null_assertion
var x13 = [(i++)!]; // ignore: unnecessary_non_null_assertion
listOfObject = x13;
}
16 changes: 8 additions & 8 deletions tests/language_2/nnbd/syntax/nullable_type_error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ main() {
// The grammar for types does not allow multiple successive ? operators on a
// type. Note: we test both with and without a space between `?`s because the
// scanner treats `??` as a single token.
int?? x1 = 0; //# 01: compile-time error
core.int?? x2 = 0; //# 02: compile-time error
List<int>?? x3 = <int>[]; //# 03: compile-time error
void Function()?? x4 = f; //# 04: compile-time error
int? ? x5 = 0; //# 05: compile-time error
core.int? ? x6 = 0; //# 06: compile-time error
List<int>? ? x7 = <int>[]; //# 07: compile-time error
void Function()? ? x4 = f; //# 08: compile-time error
int?? x1 = 0; //# 01: syntax error
core.int?? x2 = 0; //# 02: syntax error
List<int>?? x3 = <int>[]; //# 03: syntax error
void Function()?? x4 = f; //# 04: syntax error
int? ? x5 = 0; //# 05: syntax error
core.int? ? x6 = 0; //# 06: syntax error
List<int>? ? x7 = <int>[]; //# 07: syntax error
void Function()? ? x4 = f; //# 08: syntax error
}
14 changes: 7 additions & 7 deletions tests/language_2/nnbd/syntax/required_modifier_error_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

// Invalid uses of "required" modifier

required //# 01: compile-time error
required //# 01: syntax error
int f1(
required //# 02: compile-time error
required //# 02: syntax error
int x
) {}

required //# 03: compile-time error
required //# 03: syntax error
class C1 {
required //# 04: compile-time error
required //# 04: syntax error
int f2 = 0;
}

// Duplicate modifier
void f2({
required
required //# 05: compile-time error
required //# 05: syntax error
int i,
}){
}
Expand All @@ -30,8 +30,8 @@ void f2({
class C2 {
void m({
required int i1,
covariant required int i2, //# 07: compile-time error
final required int i3, //# 08: compile-time error
covariant required int i2, //# 07: syntax error
final required int i3, //# 08: syntax error
}) {
}
}
Expand Down
Loading

0 comments on commit a580529

Please sign in to comment.