Skip to content

Commit

Permalink
[CFE] Fix crash caused by name clash of loadLibrary tearoff method
Browse files Browse the repository at this point in the history
Fixes #39682

Change-Id: I0e326df9390e05ede939f0019e94f8abe1fb7983
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127460
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
  • Loading branch information
jensjoha authored and commit-bot@chromium.org committed Dec 6, 2019
1 parent 0bca6aa commit 0dc6d59
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer_fe_comparison/lib/src/kernel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class _KernelVisitor extends TreeVisitor<void> {
if (procedure.isSyntheticForwarder) {
return null;
}
if (procedure.name.name.startsWith('__loadLibrary_')) {
if (procedure.name.name.startsWith('_#loadLibrary_')) {
// Sometimes the front end generates procedures with this name that don't
// correspond to anything in the source file. Ignore them.
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LoadLibraryBuilder extends BuilderImpl {
LoadLibrary expression = createLoadLibrary(charOffset, forest, null);
String prefix = expression.import.name;
tearoff = new Procedure(
new Name('__loadLibrary_$prefix', parent.library),
new Name('_#loadLibrary_$prefix', parent.library),
ProcedureKind.Method,
new FunctionNode(new ReturnStatement(expression),
returnType: new InterfaceType(parent.loader.coreTypes.futureClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static method main() → dynamic {
#C1;
LoadLibrary(lib);
}
static method __loadLibrary_lib() → asy::Future<dynamic>*
static method _#loadLibrary_lib() → asy::Future<dynamic>*
return LoadLibrary(lib);

library deferred_lib;
Expand All @@ -18,5 +18,5 @@ static method foo() → dynamic
return null;

constants {
#C1 = tearoff self::__loadLibrary_lib
#C1 = tearoff self::_#loadLibrary_lib
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static method main() → dynamic {
#C1;
LoadLibrary(lib);
}
static method __loadLibrary_lib() → asy::Future<dynamic>*
static method _#loadLibrary_lib() → asy::Future<dynamic>*
return LoadLibrary(lib);

library deferred_lib;
Expand All @@ -18,5 +18,5 @@ static method foo() → dynamic
return null;

constants {
#C1 = tearoff self::__loadLibrary_lib
#C1 = tearoff self::_#loadLibrary_lib
}
15 changes: 15 additions & 0 deletions pkg/front_end/testcases/regress/issue_39682.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.md file.

import "issue_39682_lib.dart" deferred as foo;

main() {
var f = foo.loadLibrary;
f();
print(__loadLibrary_foo());
}

String __loadLibrary_foo() {
return "I'll call my methods what I want!";
}
16 changes: 16 additions & 0 deletions pkg/front_end/testcases/regress/issue_39682.dart.outline.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
library;
import self as self;
import "dart:core" as core;

import "org-dartlang-testcase:///issue_39682_lib.dart" deferred as foo;

static method main() → dynamic
;
static method __loadLibrary_foo() → core::String*
;

library;
import self as self2;

static method foo() → dynamic
;
29 changes: 29 additions & 0 deletions pkg/front_end/testcases/regress/issue_39682.dart.strong.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library;
import self as self;
import "dart:async" as asy;
import "dart:core" as core;

import "org-dartlang-testcase:///issue_39682_lib.dart" deferred as foo;

static method main() → dynamic {
() →* asy::Future<dynamic>* f = #C1;
f.call();
core::print(self::__loadLibrary_foo());
}
static method __loadLibrary_foo() → core::String* {
return "I'll call my methods what I want!";
}
static method _#loadLibrary_foo() → asy::Future<dynamic>*
return LoadLibrary(foo);

library;
import self as self2;
import "dart:core" as core;

static method foo() → dynamic {
core::print("foo!");
}

constants {
#C1 = tearoff self::_#loadLibrary_foo
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library;
import self as self;
import "dart:async" as asy;
import "dart:core" as core;

import "org-dartlang-testcase:///issue_39682_lib.dart" deferred as foo;

static method main() → dynamic {
() →* asy::Future<dynamic>* f = #C1;
f.call();
core::print(self::__loadLibrary_foo());
}
static method __loadLibrary_foo() → core::String* {
return "I'll call my methods what I want!";
}
static method _#loadLibrary_foo() → asy::Future<dynamic>*
return LoadLibrary(foo);

library;
import self as self2;
import "dart:core" as core;

static method foo() → dynamic {
core::print("foo!");
}

constants {
#C1 = tearoff self::_#loadLibrary_foo
}
7 changes: 7 additions & 0 deletions pkg/front_end/testcases/regress/issue_39682_lib.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 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.md file.

foo() {
print("foo!");
}
1 change: 1 addition & 0 deletions pkg/front_end/testcases/text_serialization.status
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ regress/issue_39035.crash: TextSerializationFailure
regress/issue_39040: TextSerializationFailure
regress/issue_39091_1: RuntimeError
regress/issue_39091_2: TextSerializationFailure
regress/issue_39682: TextSerializationFailure
runtime_checks/call_kinds: TextSerializationFailure # Was: Pass
runtime_checks/call_kinds_get: TextSerializationFailure # Was: Pass
runtime_checks/call_kinds_set: TextSerializationFailure # Was: Pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:expect/expect.dart' deferred as expect;

// Synthetic getter added by kernel.

/*member: __loadLibrary_expect:[null|exact=_Future]*/
/*member: _#loadLibrary_expect:[null|exact=_Future]*/

/*member: main:[null]*/
main() {
Expand Down

0 comments on commit 0dc6d59

Please sign in to comment.