From 29b5e71adaf5d9e4b20608703538387c0dac97b2 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Jul 2015 06:40:26 -0700 Subject: [PATCH] Add --supermixins option, which enables DEP 34. --- .analysis_options | 1 + lib/src/driver.dart | 4 ++ lib/src/options.dart | 9 ++++ test/all.dart | 2 + test/data/super_mixin_example.dart | 18 ++++++++ test/options_test.dart | 7 ++++ test/super_mixin_test.dart | 67 ++++++++++++++++++++++++++++++ 7 files changed, 108 insertions(+) create mode 100644 test/data/super_mixin_example.dart create mode 100644 test/super_mixin_test.dart diff --git a/.analysis_options b/.analysis_options index 1e21376..22235fb 100644 --- a/.analysis_options +++ b/.analysis_options @@ -1,3 +1,4 @@ analyzer: exclude: - test/data/no_packages_file/sdk_ext_user.dart + - test/data/super_mixin_example.dart diff --git a/lib/src/driver.dart b/lib/src/driver.dart index 73ea669..8f39619 100644 --- a/lib/src/driver.dart +++ b/lib/src/driver.dart @@ -194,6 +194,9 @@ class Driver { if (options.strongMode != _previousOptions.strongMode) { return false; } + if (options.enableSuperMixins != _previousOptions.enableSuperMixins) { + return false; + } return true; } @@ -386,6 +389,7 @@ class Driver { contextOptions.cacheSize = _maxCacheSize; contextOptions.hint = !options.disableHints; contextOptions.enableStrictCallChecks = options.enableStrictCallChecks; + contextOptions.enableSuperMixins = options.enableSuperMixins; contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy; contextOptions.generateImplicitErrors = options.showPackageWarnings; contextOptions.generateSdkErrors = options.showSdkWarnings; diff --git a/lib/src/options.dart b/lib/src/options.dart index 345eb94..2106c0d 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -42,6 +42,9 @@ class CommandLineOptions { /// "call" methods (fixes dartbug.com/21938). final bool enableStrictCallChecks; + /// Whether to relax restrictions on mixins (DEP 34). + final bool enableSuperMixins; + /// Whether to treat type mismatches found during constant evaluation as /// errors. final bool enableTypeChecks; @@ -100,6 +103,7 @@ class CommandLineOptions { displayVersion = args['version'], enableNullAwareOperators = args['enable-null-aware-operators'], enableStrictCallChecks = args['enable-strict-call-checks'], + enableSuperMixins = args['supermixin'], enableTypeChecks = args['enable_type_checks'], ignoreUnrecognizedFlags = args['ignore-unrecognized-flags'], lints = args['lints'], @@ -263,6 +267,11 @@ class CommandLineOptions { defaultsTo: false, negatable: false, hide: true) + ..addFlag('supermixin', + help: 'Relax restrictions on mixins (DEP 34).', + defaultsTo: false, + negatable: false, + hide: true) ..addFlag('log', help: 'Log additional messages and exceptions.', defaultsTo: false, diff --git a/test/all.dart b/test/all.dart index 185ebc4..8e2cf73 100644 --- a/test/all.dart +++ b/test/all.dart @@ -8,6 +8,7 @@ import 'options_test.dart' as options; import 'reporter_test.dart' as reporter; import 'sdk_ext_test.dart' as sdk_ext; import 'strong_mode_test.dart' as strong_mode; +import 'super_mixin_test.dart' as super_mixin; main() { driver.main(); @@ -16,4 +17,5 @@ main() { reporter.main(); sdk_ext.main(); strong_mode.main(); + super_mixin.main(); } diff --git a/test/data/super_mixin_example.dart b/test/data/super_mixin_example.dart new file mode 100644 index 0000000..ea90486 --- /dev/null +++ b/test/data/super_mixin_example.dart @@ -0,0 +1,18 @@ +// Copyright (c) 2015, 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. + +/// This produces errors normally, but --supermixin disables them. +class Test extends Object with C { + void foo() {} +} + +abstract class B { + void foo(); +} + +abstract class C extends B { + void bar() { + super.foo(); + } +} diff --git a/test/options_test.dart b/test/options_test.dart index 151bb3c..e308442 100644 --- a/test/options_test.dart +++ b/test/options_test.dart @@ -22,6 +22,7 @@ main() { expect(options.lints, isFalse); expect(options.displayVersion, isFalse); expect(options.enableStrictCallChecks, isFalse); + expect(options.enableSuperMixins, isFalse); expect(options.enableTypeChecks, isFalse); expect(options.ignoreUnrecognizedFlags, isFalse); expect(options.log, isFalse); @@ -56,6 +57,12 @@ main() { expect(options.enableStrictCallChecks, isTrue); }); + test('enable super mixins', () { + CommandLineOptions options = CommandLineOptions + .parse(['--dart-sdk', '.', '--supermixin', 'foo.dart']); + expect(options.enableSuperMixins, isTrue); + }); + test('enable type checks', () { CommandLineOptions options = CommandLineOptions .parse(['--dart-sdk', '.', '--enable_type_checks', 'foo.dart']); diff --git a/test/super_mixin_test.dart b/test/super_mixin_test.dart new file mode 100644 index 0000000..6b397fa --- /dev/null +++ b/test/super_mixin_test.dart @@ -0,0 +1,67 @@ +// Copyright (c) 2015, 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. + +@TestOn("vm") +library analyzer_cli.test.super_mixin; + +import 'dart:io'; + +import 'package:analyzer_cli/src/driver.dart' show Driver, errorSink, outSink; +import 'package:path/path.dart' as path; +import 'package:test/test.dart'; + +import 'utils.dart'; + +/// End-to-end test for --strong checking. +/// +/// Most StrongChecker tests are in dev_compiler/test/checker/*_test.dart, but +/// this verifies the option is working and producing extra errors as expected. +/// +/// Generally we don't want a lot of cases here as it requires spinning up a +/// full analysis context. +void main() { + group('--supermixins', () { + StringSink savedOutSink, savedErrorSink; + int savedExitCode; + setUp(() { + savedOutSink = outSink; + savedErrorSink = errorSink; + savedExitCode = exitCode; + outSink = new StringBuffer(); + errorSink = new StringBuffer(); + }); + tearDown(() { + outSink = savedOutSink; + errorSink = savedErrorSink; + exitCode = savedExitCode; + }); + + test('produces errors when option absent', () async { + var testPath = path.join(testDirectory, 'data/super_mixin_example.dart'); + new Driver().start([testPath]); + + expect(exitCode, 3); + var stdout = outSink.toString(); + expect( + stdout, + contains( + "[error] The class 'C' cannot be used as a mixin because it extends a class other than Object")); + expect( + stdout, + contains( + "[error] The class 'C' cannot be used as a mixin because it references 'super'")); + expect(stdout, contains('2 errors found.')); + expect(errorSink.toString(), ''); + }); + + test('produces no errors when option present', () async { + var testPath = path.join(testDirectory, 'data/super_mixin_example.dart'); + new Driver().start(['--supermixin', testPath]); + + expect(exitCode, 0); + var stdout = outSink.toString(); + expect(stdout, contains('No issues found')); + }); + }); +}