mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
Revert "[dartdevc] fix for const / overridden fields"
This is breaking Flutter Web - see: https://github.com/flutter/flutter/issues/40876 Will need to reopen: https://github.com/dart-lang/sdk/issues/38455 Change-Id: I6942cdc136533286c3a5eee93439d4f0f9beb28b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118261 Reviewed-by: Vijay Menon <vsm@google.com> Reviewed-by: Mark Zhou <markzipan@google.com> Commit-Queue: Vijay Menon <vsm@google.com>
This commit is contained in:
parent
ff0e8f8035
commit
43cacafb51
4 changed files with 6 additions and 53 deletions
|
@ -252,7 +252,6 @@ abstract class SharedCompiler<Library, Class, InterfaceType, FunctionNode> {
|
|||
/// runtime call.
|
||||
js_ast.TemporaryId initPrivateNameSymbol() {
|
||||
var idName = name.endsWith('=') ? name.replaceAll('=', '_') : name;
|
||||
idName = idName.replaceAll('.', '_');
|
||||
var id = js_ast.TemporaryId(idName);
|
||||
moduleItems.add(js.statement('const # = #.privateName(#, #)',
|
||||
[id, runtimeModule, emitLibraryName(library), js.string(name)]));
|
||||
|
@ -263,16 +262,6 @@ abstract class SharedCompiler<Library, Class, InterfaceType, FunctionNode> {
|
|||
return privateNames.putIfAbsent(name, initPrivateNameSymbol);
|
||||
}
|
||||
|
||||
/// Emits a private name JS Symbol for [name] unique to a Dart class [cls].
|
||||
///
|
||||
/// This is now required for fields of constant objects that may be
|
||||
/// overridden within the same library.
|
||||
@protected
|
||||
js_ast.TemporaryId emitClassPrivateNameSymbol(
|
||||
Library library, String className, String memberName) {
|
||||
return emitPrivateNameSymbol(library, '$className.$memberName');
|
||||
}
|
||||
|
||||
/// Emits an expression to set the property [nameExpr] on the class [className],
|
||||
/// with [value].
|
||||
///
|
||||
|
|
|
@ -2796,9 +2796,10 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
|
||||
void _emitVirtualFieldSymbols(Class c, List<js_ast.Statement> body) {
|
||||
_classProperties.virtualFields.forEach((field, virtualField) {
|
||||
var symbol = emitClassPrivateNameSymbol(
|
||||
c.enclosingLibrary, getLocalClassName(c), field.name.name);
|
||||
body.add(js.statement('const # = #;', [virtualField, symbol]));
|
||||
body.add(js.statement('const # = Symbol(#);', [
|
||||
virtualField,
|
||||
js.string('${getLocalClassName(c)}.${field.name.name}')
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -5407,15 +5408,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
entryToProperty(MapEntry<Reference, Constant> entry) {
|
||||
var constant = visitConstant(entry.value);
|
||||
var member = entry.key.asField;
|
||||
var cls = member.enclosingClass;
|
||||
// Enums cannot be overridden, so we can safely use the field name
|
||||
// directly. Otherwise, use a private symbol in case the field
|
||||
// was overridden.
|
||||
var symbol = cls.isEnum
|
||||
? _emitMemberName(member.name.name, member: member)
|
||||
: emitClassPrivateNameSymbol(
|
||||
cls.enclosingLibrary, getLocalClassName(cls), member.name.name);
|
||||
return js_ast.Property(symbol, constant);
|
||||
return js_ast.Property(
|
||||
_emitMemberName(member.name.name, member: member), constant);
|
||||
}
|
||||
|
||||
var type = visitInterfaceType(node.getType(_types) as InterfaceType);
|
||||
|
|
|
@ -161,13 +161,6 @@ class _LibraryVirtualFieldModel {
|
|||
if (_extensiblePrivateClasses.contains(class_)) return true;
|
||||
}
|
||||
|
||||
if (class_.constructors.any((c) => c.isConst)) {
|
||||
// Always virtualize fields of a (might be) non-enum (see above) const
|
||||
// class. The way these are lowered by the CFE, they need to be
|
||||
// writable from different modules even if overridden.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, the field is effectively private and we only need to make it
|
||||
// virtual if it's overridden.
|
||||
return _overriddenPrivateFields.contains(field);
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
// 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.
|
||||
// Dart test checking that static/instance field shadowing do not conflict.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class A {
|
||||
final field;
|
||||
const A(this.field);
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
final field;
|
||||
const B(this.field, fieldA) : super(fieldA);
|
||||
get fieldA => super.field;
|
||||
}
|
||||
|
||||
main() {
|
||||
const b = B(1, 2);
|
||||
Expect.equals(1, b.field);
|
||||
Expect.equals(2, b.fieldA);
|
||||
}
|
Loading…
Reference in a new issue