Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

fix issue in const error handling #1045

Merged
merged 3 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/src/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class HasConstErrorListener extends AnalysisErrorListener {

@override
void onError(AnalysisError error) {
hasConstError = errorCodes.contains(error.errorCode);
hasConstError = hasConstError || errorCodes.contains(error.errorCode);
}

static const List<CompileTimeErrorCode> errorCodes = const [
Expand All @@ -340,6 +340,7 @@ class HasConstErrorListener extends AnalysisErrorListener {
CompileTimeErrorCode.INVALID_CONSTANT,
CompileTimeErrorCode.MISSING_CONST_IN_LIST_LITERAL,
CompileTimeErrorCode.MISSING_CONST_IN_MAP_LITERAL,
CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION,
CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT,
CompileTimeErrorCode.NON_CONSTANT_MAP_KEY,
CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE,
Expand Down
2 changes: 2 additions & 0 deletions test/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:analyzer/src/lint/io.dart';

import 'ast_test.dart' as ast_test;
import 'engine_test.dart' as engine_test;
import 'formatter_test.dart' as formatter_test;
import 'integration_test.dart' as integration_test;
Expand All @@ -17,6 +18,7 @@ main() {
// Redirect output.
outSink = new MockIOSink();

ast_test.main();
engine_test.main();
formatter_test.main();
integration_test.main();
Expand Down
27 changes: 27 additions & 0 deletions test/ast_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:analyzer/analyzer.dart';
import 'package:linter/src/ast.dart';
import 'package:test/test.dart';

main() {
group('HasConstErrorListener', () {
test('has hasConstError false by default', () {
final listener = new HasConstErrorListener();
expect(listener.hasConstError, isFalse);
});
test('has hasConstError true with a tracked const error', () {
final listener = new HasConstErrorListener();
listener.onError(new AnalysisError(
null, null, null, CompileTimeErrorCode.CONST_WITH_NON_CONST));
expect(listener.hasConstError, isTrue);
});
test('has hasConstError true even if last error is not related to const',
() {
final listener = new HasConstErrorListener();
listener.onError(new AnalysisError(
null, null, null, CompileTimeErrorCode.CONST_WITH_NON_CONST));
listener.onError(new AnalysisError(
null, null, null, CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD));
expect(listener.hasConstError, isTrue);
});
});
}