Skip to content

Commit

Permalink
Issue 40701. Include 'late' into unlinked API signature.
Browse files Browse the repository at this point in the history
R=brianwilkerson@google.com, pquitslund@google.com

Bug: #40701
Change-Id: Ia11ff4e65e779c4a370a6fec539564c0533bffa3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136529
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and commit-bot@chromium.org committed Feb 20, 2020
1 parent 6da0090 commit 81d4cc6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ typedef WorkToWaitAfterComputingResult = Future<void> Function(String path);
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
class AnalysisDriver implements AnalysisDriverGeneric {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 96;
static const int DATA_VERSION = 97;

/// The length of the list returned by [_computeDeclaredVariablesSignature].
static const int _declaredVariablesSignatureLength = 4;
Expand Down
4 changes: 3 additions & 1 deletion pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10482,7 +10482,9 @@ class VariableDeclarationListImpl extends AnnotatedNodeImpl

@override
Token get firstTokenAfterCommentAndMetadata {
if (keyword != null) {
if (lateKeyword != null) {
return lateKeyword;
} else if (keyword != null) {
return keyword;
} else if (_type != null) {
return _type.beginToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// 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.

import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/src/dart/analysis/unlinked_api_signature.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

Expand All @@ -11,6 +13,7 @@ import '../ast/parse_base.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(UnitApiSignatureTest);
defineReflectiveTests(UnitApiSignatureWithNullSafetyTest);
});
}

Expand Down Expand Up @@ -199,6 +202,30 @@ class B extends A {}
''');
}

test_class_field_final_add() {
assertNotSameSignature(r'''
class C {
int a = 0;
}
''', r'''
class C {
final int a = 0;
}
''');
}

test_class_field_static_add() {
assertNotSameSignature(r'''
class C {
int a;
}
''', r'''
class C {
static int a;
}
''');
}

test_class_field_withoutType() {
assertNotSameSignature(r'''
class C {
Expand Down Expand Up @@ -790,7 +817,7 @@ class A {}
// @dart = 2.6
class A {}
''', r'''
// @dart = 2.5
// @dart = 2.2
class A {}
''');
}
Expand Down Expand Up @@ -1011,6 +1038,14 @@ mixin M on A {}
''');
}

test_topLevelVariable_final_add() {
assertNotSameSignature(r'''
int a = 0;
''', r'''
final int a = 0;
''');
}

test_topLevelVariable_withoutType() {
assertNotSameSignature(r'''
var a = 1;
Expand Down Expand Up @@ -1075,3 +1110,51 @@ typedef F = void Function(double);
''');
}
}

@reflectiveTest
class UnitApiSignatureWithNullSafetyTest extends UnitApiSignatureTest {
@override
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
..contextFeatures = FeatureSet.forTesting(
sdkVersion: '2.3.0', additionalFeatures: [Feature.non_nullable]);

test_class_field_late_add() {
assertNotSameSignature(r'''
class C {
int a;
}
''', r'''
class C {
late int a;
}
''');
}

test_class_field_late_remove() {
assertNotSameSignature(r'''
class C {
late int a;
}
''', r'''
class C {
int a;
}
''');
}

test_topLevelVariable_late_add() {
assertNotSameSignature(r'''
int a;
''', r'''
late int a;
''');
}

test_topLevelVariable_late_remove() {
assertNotSameSignature(r'''
late int a;
''', r'''
int a;
''');
}
}

0 comments on commit 81d4cc6

Please sign in to comment.