From 3c0ffbb1443d019b0748626d4c9e536373493f2e Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Fri, 27 Jan 2023 12:02:54 -0800 Subject: [PATCH 1/3] Validate only needed summaries in expression_compiler_service --- dwds/lib/src/services/expression_compiler_service.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dwds/lib/src/services/expression_compiler_service.dart b/dwds/lib/src/services/expression_compiler_service.dart index 74cd13510..e94be84c3 100644 --- a/dwds/lib/src/services/expression_compiler_service.dart +++ b/dwds/lib/src/services/expression_compiler_service.dart @@ -71,7 +71,12 @@ class _Compiler { List experiments, bool verbose, ) async { - sdkConfiguration.validate(); + sdkConfiguration.validateSdkDir(); + if (soundNullSafety) { + sdkConfiguration.validateSoundSummaries(); + } else { + sdkConfiguration.validateWeakSummaries(); + } final librariesUri = sdkConfiguration.librariesUri!; final workerUri = sdkConfiguration.compilerWorkerUri!; From ed50aae996baeca5592f18477204446e07ca2df0 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Sat, 28 Jan 2023 18:59:27 -0800 Subject: [PATCH 2/3] Make webdev tests use sound null safe fixtures --- dwds/CHANGELOG.md | 1 + fixtures/_webdevSoundSmoke/web/scopes.html | 7 + .../_webdevSoundSmoke/web/scopes_main.dart | 152 ++++++++++++++++++ webdev/test/daemon/utils.dart | 2 +- 4 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 fixtures/_webdevSoundSmoke/web/scopes.html create mode 100644 fixtures/_webdevSoundSmoke/web/scopes_main.dart diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index cd411a853..c2f0dd834 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -19,6 +19,7 @@ - Return error on expression evaluation if expression evaluator stopped. - Update SDK constraint to `>=3.0.0-134.0.dev <4.0.0`. - Update `package:vm_service` constraint to `>=10.1.0 <12.0.0`. +- Fix expression compiler throwing when weak SDK summary is not found. **Breaking changes** - Include an optional param to `Dwds.start` to indicate whether it is running diff --git a/fixtures/_webdevSoundSmoke/web/scopes.html b/fixtures/_webdevSoundSmoke/web/scopes.html new file mode 100644 index 000000000..6c3307394 --- /dev/null +++ b/fixtures/_webdevSoundSmoke/web/scopes.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/fixtures/_webdevSoundSmoke/web/scopes_main.dart b/fixtures/_webdevSoundSmoke/web/scopes_main.dart new file mode 100644 index 000000000..228b1f2c6 --- /dev/null +++ b/fixtures/_webdevSoundSmoke/web/scopes_main.dart @@ -0,0 +1,152 @@ +// Copyright (c) 2020, 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. + +/// An example with more complicated scope +import 'dart:async'; +import 'dart:collection'; + +final libraryPublicFinal = MyTestClass(); + +final _libraryPrivateFinal = 1; +Object? libraryNull; +var libraryPublic = ['library', 'public', 'variable']; +var notAList = NotReallyAList(); + +var _libraryPrivate = ['library', 'private', 'variable']; + +var identityMap = {}; + +var map = {}; + +void staticFunction(int formal) { + print(formal); // Breakpoint: staticFunction +} + +void main() async { + print('Initial print from scopes app'); + var local = 'local in main'; + var intLocalInMain = 42; + var testClass = MyTestClass(); + Object? localThatsNull; + identityMap['a'] = 1; + identityMap['b'] = 2; + map['a'] = [1, 2, 3]; + map['b'] = 'something'; + notAList.add(7); + + String nestedFunction(T parameter, Object aClass) { + var another = int.tryParse('$parameter'); + return '$local: parameter, $another'; // Breakpoint: nestedFunction + } + + dynamic nestedWithClosure(String banana) { + return () => '$local + $banana'; + } + + Timer.periodic(const Duration(seconds: 1), (Timer t) { + var ticks = t.tick; + // ignore: unused_local_variable, prefer_typing_uninitialized_variables + var closureLocal; + libraryPublicFinal.printCount(); + staticFunction(1); + print('ticking... $ticks (the answer is $intLocalInMain)'); + print(nestedFunction('$ticks ${testClass.message}', Timer)); + print(localThatsNull); + print(libraryNull); + var localList = libraryPublic; + print(localList); + localList.add('abc'); + var f = testClass.methodWithVariables(); + print(f('parameter')); + }); + + print(_libraryPrivateFinal); + print(_libraryPrivate); + print(nestedFunction(_libraryPrivate.first, Object)); + print(nestedWithClosure(_libraryPrivate.first)()); +} + +String libraryFunction(String arg) { + print('calling a library function with $arg'); + var concat = 'some constant plus $arg plus whatever'; + print(concat); + return concat; +} + +class MyTestClass { + final String message; + + late String notFinal; + + MyTestClass({this.message = 'world'}) { + myselfField = this; + tornOff = toString; + } + + String hello() => message; + + String Function(String) methodWithVariables() { + var local = '$message + something'; + print(local); + return (String parameter) { + // Be sure to use a field from this, so it isn't entirely optimized away. + var closureLocalInsideMethod = '$message/$local/$parameter'; + print(closureLocalInsideMethod); + return closureLocalInsideMethod; // Breakpoint: nestedClosure + }; + } + + //ignore: avoid_returning_this + MyTestClass get myselfGetter => this; + + late MyTestClass myselfField; + + var count = 0; + + // An easy location to add a breakpoint. + void printCount() { + print('The count is ${++count}'); + libraryFunction('abc'); // Breakpoint: printMethod + } + + final _privateField = 'a private field'; + + // ignore: unused_element + String privateMethod(String s) => '$s : $_privateField'; + + @override + String toString() => 'A test class with message $message'; + + bool equals(Object other) { + if (other is MyTestClass) return message == other.hello(); + return false; + } + + Function closure = someFunction; + + late String Function() tornOff; +} + +Function? someFunction() => null; + +// ignore: unused_element +int _libraryPrivateFunction(int a, int b) => a + b; + +class NotReallyAList extends ListBase { + final List _internal; + + NotReallyAList() : _internal = []; + + @override + Object? operator [](x) => _internal[x]; + + @override + operator []=(x, y) => _internal[x] = y as Object?; + + @override + int get length => _internal.length; + + @override + set length(x) => _internal.length = x; +} diff --git a/webdev/test/daemon/utils.dart b/webdev/test/daemon/utils.dart index fcb21d53b..f124a2fcd 100644 --- a/webdev/test/daemon/utils.dart +++ b/webdev/test/daemon/utils.dart @@ -39,7 +39,7 @@ Future waitForAppId(TestProcess webdev) async { Future prepareWorkspace() async { var exampleDirectory = - p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSmoke')); + p.absolute(p.join(p.current, '..', 'fixtures', '_webdevSoundSmoke')); var process = await TestProcess.start(dartPath, ['pub', 'upgrade'], workingDirectory: exampleDirectory, environment: getPubEnvironment()); From 9be86455eef52a8a1d1ff929d9e96885a6743441 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Sat, 28 Jan 2023 19:17:40 -0800 Subject: [PATCH 3/3] Updated changelog --- webdev/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/webdev/CHANGELOG.md b/webdev/CHANGELOG.md index b3223a0dd..7c117f3d5 100644 --- a/webdev/CHANGELOG.md +++ b/webdev/CHANGELOG.md @@ -4,6 +4,7 @@ to the build runner and the expression compiler service. - Update SDK constraint to `>=3.0.0-134.0.dev <4.0.0`. - Update `package:vm_service` constraint to `>=10.1.0 <12.0.0`. +- Make all tests use sound null safety fixtures. **Breaking changes**