Skip to content

Commit 24725a8

Browse files
sjindel-googlecommit-bot@chromium.org
authored andcommitted
[cfe] Fix handling of private names in expression evaluation.
Issue: dartbug.com/35505 Change-Id: Ia1d211247852ef116139f8b509c21410fc8629d8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108606 Commit-Queue: Samir Jindel <[email protected]> Reviewed-by: Jens Johansen <[email protected]>
1 parent cb93b8d commit 24725a8

24 files changed

+151
-16
lines changed

pkg/front_end/lib/src/fasta/incremental_compiler.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -743,11 +743,13 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
743743
}
744744

745745
KernelLibraryBuilder debugLibrary = new KernelLibraryBuilder(
746-
libraryUri,
747-
debugExprUri,
748-
userCode.loader,
749-
null,
750-
library.scope.createNestedScope("expression"));
746+
libraryUri,
747+
debugExprUri,
748+
userCode.loader,
749+
null,
750+
scope: library.scope.createNestedScope("expression"),
751+
nameOrigin: library.target,
752+
);
751753

752754
if (library is DillLibraryBuilder) {
753755
for (LibraryDependency dependency in library.target.dependencies) {

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,14 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
496496
expression = new UnresolvedNameGenerator(
497497
this,
498498
deprecated_extractToken(identifier),
499-
new Name(identifier.name, library.library));
499+
new Name(identifier.name, library.nameOrigin));
500500
}
501501
if (name?.isNotEmpty ?? false) {
502502
Token period = periodBeforeName ?? beginToken.next.next;
503503
Generator generator = expression;
504504
expression = generator.buildPropertyAccess(
505505
new IncompletePropertyAccessGenerator(
506-
this, period.next, new Name(name, library.library)),
506+
this, period.next, new Name(name, library.nameOrigin)),
507507
period.next.offset,
508508
false);
509509
}
@@ -1297,7 +1297,7 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
12971297
assert(typeArguments == null);
12981298
}
12991299
if (receiver is Identifier) {
1300-
Name name = new Name(receiver.name, library.library);
1300+
Name name = new Name(receiver.name, library.nameOrigin);
13011301
if (arguments == null) {
13021302
push(new IncompletePropertyAccessGenerator(this, beginToken, name));
13031303
} else {
@@ -1495,7 +1495,7 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
14951495
if (periodIndex != -1) {
14961496
length -= periodIndex + 1;
14971497
}
1498-
Name kernelName = new Name(name, library.library);
1498+
Name kernelName = new Name(name, library.nameOrigin);
14991499
List<LocatedMessage> context;
15001500
if (candidate != null && candidate.location != null) {
15011501
Uri uri = candidate.location.file;
@@ -1765,7 +1765,7 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
17651765
}
17661766
if (declaration == null ||
17671767
(!isInstanceContext && declaration.isInstanceMember)) {
1768-
Name n = new Name(name, library.library);
1768+
Name n = new Name(name, library.nameOrigin);
17691769
if (!isQualified && isInstanceContext) {
17701770
assert(declaration == null);
17711771
if (constantContext != ConstantContext.none || member.isField) {
@@ -1817,7 +1817,7 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
18171817
addProblem(
18181818
fasta.messageNotAConstantExpression, charOffset, token.length);
18191819
}
1820-
Name n = new Name(name, library.library);
1820+
Name n = new Name(name, library.nameOrigin);
18211821
Member getter;
18221822
Member setter;
18231823
if (declaration is AccessErrorBuilder) {

pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ class KernelLibraryBuilder
192192
// TODO(dmitryas): Find a way to mark inferred types.
193193
final Set<DartType> inferredTypes = new Set<DartType>.identity();
194194

195+
// A library to use for Names generated when compiling code in this library.
196+
// This allows code generated in one library to use the private namespace of
197+
// another, for example during expression compilation (debugging).
198+
Library get nameOrigin => _nameOrigin ?? library;
199+
final Library _nameOrigin;
200+
195201
/// Exports that can't be serialized.
196202
///
197203
/// The key is the name of the exported member.
@@ -208,9 +214,10 @@ class KernelLibraryBuilder
208214
List<KernelFieldBuilder> implicitlyTypedFields;
209215

210216
KernelLibraryBuilder(Uri uri, Uri fileUri, Loader loader, this.actualOrigin,
211-
[Scope scope, Library target])
217+
{Scope scope, Library target, Library nameOrigin})
212218
: library = target ??
213219
(actualOrigin?.library ?? new Library(uri, fileUri: fileUri)),
220+
_nameOrigin = nameOrigin,
214221
super(loader, fileUri, scope);
215222

216223
@override

pkg/front_end/test/fasta/generator_to_string_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ main() {
104104
new NoneTarget(new TargetFlags(legacyMode: true))),
105105
null)
106106
.loader,
107-
null,
108107
null);
109108
LoadLibraryBuilder loadLibraryBuilder =
110109
new LoadLibraryBuilder(libraryBuilder, null, -1);

pkg/front_end/test/fasta/unlinked_scope_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class MockLibraryBuilder extends KernelLibraryBuilder {
5353
new NoneTarget(new TargetFlags(legacyMode: true))),
5454
null)
5555
.loader,
56-
null,
5756
null);
5857

5958
KernelProcedureBuilder mockProcedure(String name) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
5+
entry_point: "main.dart"
6+
definitions: []
7+
position: "main.dart#B"
8+
expression: |
9+
_priv
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Errors: {
2+
}
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic
4+
return this.{main::B::_priv};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
5+
entry_point: "main.dart"
6+
definitions: []
7+
position: "main.dart#B"
8+
expression: |
9+
_privMethod
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Errors: {
2+
}
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic
4+
return this.{main::B::_privMethod};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
5+
entry_point: "main.dart"
6+
definitions: []
7+
position: "main.dart#B"
8+
expression: |
9+
_priv = 3

0 commit comments

Comments
 (0)