From 9ac7bd78550ac5c73b2131a71751a30e6ae967e7 Mon Sep 17 00:00:00 2001 From: Sigmund Cherem Date: Mon, 6 May 2019 21:43:42 +0000 Subject: [PATCH] Ensure we have a scope for variables when visiting fields Fixes https://github.com/dart-lang/sdk/issues/36864 Change-Id: I66d70cc30b26bd069d4ab5e2b98f0f5954f3ef59 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101460 Auto-Submit: Sigmund Cherem Commit-Queue: Johnni Winther Reviewed-by: Johnni Winther --- pkg/compiler/lib/src/ir/static_type.dart | 3 +++ .../block_expression_on_field_test.dart | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/compiler/dart2js_extra/block_expression_on_field_test.dart diff --git a/pkg/compiler/lib/src/ir/static_type.dart b/pkg/compiler/lib/src/ir/static_type.dart index 21b7964dc662..63eefbc8b05c 100644 --- a/pkg/compiler/lib/src/ir/static_type.dart +++ b/pkg/compiler/lib/src/ir/static_type.dart @@ -1401,8 +1401,11 @@ abstract class StaticTypeVisitor extends StaticTypeBase { @override Null visitField(ir.Field node) { thisType = new ThisInterfaceType.from(node.enclosingClass?.thisType); + _currentVariables = new Set(); visitNode(node.initializer); handleField(node); + _invalidatedVariables.removeAll(_currentVariables); + _currentVariables = null; thisType = null; } diff --git a/tests/compiler/dart2js_extra/block_expression_on_field_test.dart b/tests/compiler/dart2js_extra/block_expression_on_field_test.dart new file mode 100644 index 000000000000..7b6449f9358d --- /dev/null +++ b/tests/compiler/dart2js_extra/block_expression_on_field_test.dart @@ -0,0 +1,27 @@ +// 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. + +/// Regression test for #36864 +/// +/// Block expressions in top-level fields used to crash the compiler. +import "package:expect/expect.dart"; + +final _a = { + ...{1} +}; + +class B { + static Set _b = { + ...{2} + }; + Set _c = { + ...{3} + }; +} + +main() { + Expect.setEquals({1}, _a); + Expect.setEquals({2}, B._b); + Expect.setEquals({3}, (new B()._c)); +}