Index: lib/compiler/implementation/compiler.dart |
diff --git a/lib/compiler/implementation/compiler.dart b/lib/compiler/implementation/compiler.dart |
index 6b130e442bb074e78040abd5a662f3bb11e6d8d2..1f060b13f65c78825f04b1c2c2b8ab4ec6acb344 100644 |
--- a/lib/compiler/implementation/compiler.dart |
+++ b/lib/compiler/implementation/compiler.dart |
@@ -534,7 +534,7 @@ class Compiler implements DiagnosticListener { |
Uri resolved = patchBase.resolve(argument.dartString.slowToString()); |
LibraryElement importedLibrary = |
scanner.loadLibrary(resolved, argument); |
- scanner.importLibrary(original, importedLibrary, tag, patch); |
+ scanner.importLibrary(original, importedLibrary, tag, patch.script); |
if (resolved.scheme == "dart") { |
delayedPatches[resolved.path] = importedLibrary; |
} |
@@ -588,11 +588,20 @@ class Compiler implements DiagnosticListener { |
} |
} |
} else if (originalElement === null) { |
+ // The original library does not have an element with the same name |
+ // as the patch library element. |
+ // In this case, the patch library element must not be marked as |
+ // "patch", and its name must make it private. |
if (isPatchElement(patchElement)) { |
internalError("Cannot patch non-existing member '" |
"${patchElement.name.slowToString()}'."); |
} |
- original.addMember(clonePatch(patchElement), this); |
+ if (!patchElement.name.isPrivate()) { |
+ internalError("Cannot add non-private member '" |
+ "${patchElement.name.slowToString()}' from patch."); |
+ } |
+ Element cloneElement = patchElement.cloneTo(original, this); |
+ original.addMember(cloneElement, this); |
} else { |
patchMember(originalElement, patchElement); |
} |
@@ -606,20 +615,6 @@ class Compiler implements DiagnosticListener { |
return !element.metadata.isEmpty(); |
} |
- Element clonePatch(Element patchElement) { |
- // The original library does not have an element with the same name |
- // as the patch library element. |
- // In this case, the patch library element must not be marked as "patch", |
- // and its name must make it private. |
- if (!patchElement.name.isPrivate()) { |
- internalError("Cannot add non-private member '" |
- "${patchElement.name.slowToString()}' from patch."); |
- } |
- // TODO(lrn): Create a copy of patchElement that isn't added to any |
- // object/library yet, but which takes its source from patchElement. |
- throw "Adding members from patch is unsupported"; |
- } |
- |
void patchMember(Element originalElement, Element patchElement) { |
// The original library has an element with the same name as the patch |
// library element. |
@@ -978,7 +973,7 @@ class Compiler implements DiagnosticListener { |
throw 'Cannot find tokens to produce error message.'; |
} |
if (uri === null && currentElement !== null) { |
- uri = currentElement.getCompilationUnit().script.uri; |
+ uri = currentElement.getScript().uri; |
} |
return SourceSpan.withCharacterOffsets(begin, end, |
(beginOffset, endOffset) => new SourceSpan(uri, beginOffset, endOffset)); |
@@ -1002,7 +997,7 @@ class Compiler implements DiagnosticListener { |
element = currentElement; |
} |
Token position = element.position(); |
- Uri uri = element.getCompilationUnit().script.uri; |
+ Uri uri = element.getScript().uri; |
return (position === null) |
? new SourceSpan(uri, 0, 0) |
: spanFromTokens(position, position, uri); |