First pass at asynchronous input loading in dart2js.
R=ahe@google.com, johnniwinther@google.com Review URL: https://codereview.chromium.org//17759007 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27028 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
@@ -61,3 +61,8 @@ void asyncEnd() {
|
||||
print('unittest-suite-success');
|
||||
}
|
||||
}
|
||||
|
||||
void asyncTest(Future f()) {
|
||||
asyncStart();
|
||||
f().whenComplete(() => asyncEnd());
|
||||
}
|
||||
@@ -92,19 +92,21 @@ Future<String> compile(Uri script,
|
||||
libraryRoot,
|
||||
packageRoot,
|
||||
options);
|
||||
compiler.run(script);
|
||||
String code = compiler.assembledCode;
|
||||
if (code != null && outputProvider != null) {
|
||||
String outputType = 'js';
|
||||
if (options.contains('--output-type=dart')) {
|
||||
outputType = 'dart';
|
||||
// TODO(ahe): Use the value of the future (which signals success or failure).
|
||||
return compiler.run(script).then((_) {
|
||||
String code = compiler.assembledCode;
|
||||
if (code != null && outputProvider != null) {
|
||||
String outputType = 'js';
|
||||
if (options.contains('--output-type=dart')) {
|
||||
outputType = 'dart';
|
||||
}
|
||||
outputProvider('', outputType)
|
||||
..add(code)
|
||||
..close();
|
||||
code = ''; // Non-null signals success.
|
||||
}
|
||||
outputProvider('', outputType)
|
||||
..add(code)
|
||||
..close();
|
||||
code = ''; // Non-null signals success.
|
||||
}
|
||||
return new Future.value(code);
|
||||
return code;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -133,12 +133,10 @@ class Compiler extends leg.Compiler {
|
||||
return "lib/$path";
|
||||
}
|
||||
|
||||
elements.LibraryElement scanBuiltinLibrary(String path) {
|
||||
Future<elements.LibraryElement> scanBuiltinLibrary(String path) {
|
||||
Uri uri = libraryRoot.resolve(lookupLibraryPath(path));
|
||||
Uri canonicalUri = new Uri(scheme: "dart", path: path);
|
||||
elements.LibraryElement library =
|
||||
libraryLoader.loadLibrary(uri, null, canonicalUri);
|
||||
return library;
|
||||
return libraryLoader.loadLibrary(uri, null, canonicalUri);
|
||||
}
|
||||
|
||||
void log(message) {
|
||||
@@ -157,30 +155,37 @@ class Compiler extends leg.Compiler {
|
||||
/**
|
||||
* Reads the script designated by [readableUri].
|
||||
*/
|
||||
leg.Script readScript(Uri readableUri, [tree.Node node]) {
|
||||
Future<leg.Script> readScript(Uri readableUri,
|
||||
[elements.Element element, tree.Node node]) {
|
||||
if (!readableUri.isAbsolute) {
|
||||
internalError('Relative uri $readableUri provided to readScript(Uri)',
|
||||
node: node);
|
||||
}
|
||||
return fileReadingTask.measure(() {
|
||||
Uri resourceUri = translateUri(readableUri, node);
|
||||
String text = "";
|
||||
try {
|
||||
// TODO(ahe): We expect the future to be complete and call value
|
||||
// directly. In effect, we don't support truly asynchronous API.
|
||||
text = deprecatedFutureValue(provider(resourceUri));
|
||||
} catch (exception) {
|
||||
|
||||
// TODO(johnniwinther): Add [:report(..., {Element element}):] to
|
||||
// report methods in Compiler.
|
||||
void reportReadError(String exception) {
|
||||
withCurrentElement(element, () {
|
||||
reportError(node,
|
||||
leg.MessageKind.READ_SCRIPT_ERROR,
|
||||
{'uri': readableUri, 'exception': exception});
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Uri resourceUri = translateUri(readableUri, node);
|
||||
// TODO(johnniwinther): Wrap the result from [provider] in a specialized
|
||||
// [Future] to ensure that we never execute an asynchronous action without setting
|
||||
// up the current element of the compiler.
|
||||
return new Future.sync(() => provider(resourceUri)).then((String text) {
|
||||
SourceFile sourceFile = new SourceFile(resourceUri.toString(), text);
|
||||
// We use [readableUri] as the URI for the script since need to preserve
|
||||
// the scheme in the script because [Script.uri] is used for resolving
|
||||
// relative URIs mentioned in the script. See the comment on
|
||||
// [LibraryLoader] for more details.
|
||||
return new leg.Script(readableUri, sourceFile);
|
||||
}).catchError((error) {
|
||||
reportReadError(error);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -254,18 +259,19 @@ class Compiler extends leg.Compiler {
|
||||
return packageRoot.resolve(uri.path);
|
||||
}
|
||||
|
||||
bool run(Uri uri) {
|
||||
Future<bool> run(Uri uri) {
|
||||
log('Allowed library categories: $allowedLibraryCategories');
|
||||
bool success = super.run(uri);
|
||||
int cumulated = 0;
|
||||
for (final task in tasks) {
|
||||
cumulated += task.timing;
|
||||
log('${task.name} took ${task.timing}msec');
|
||||
}
|
||||
int total = totalCompileTime.elapsedMilliseconds;
|
||||
log('Total compile-time ${total}msec;'
|
||||
' unaccounted ${total - cumulated}msec');
|
||||
return success;
|
||||
return super.run(uri).then((bool success) {
|
||||
int cumulated = 0;
|
||||
for (final task in tasks) {
|
||||
cumulated += task.timing;
|
||||
log('${task.name} took ${task.timing}msec');
|
||||
}
|
||||
int total = totalCompileTime.elapsedMilliseconds;
|
||||
log('Total compile-time ${total}msec;'
|
||||
' unaccounted ${total - cumulated}msec');
|
||||
return success;
|
||||
});
|
||||
}
|
||||
|
||||
void reportDiagnostic(leg.SourceSpan span, String message,
|
||||
|
||||
@@ -36,7 +36,6 @@ abstract class WorkItem {
|
||||
assert(invariant(element, element.isDeclaration));
|
||||
}
|
||||
|
||||
|
||||
void run(Compiler compiler, Enqueuer world);
|
||||
}
|
||||
|
||||
@@ -81,11 +80,6 @@ class PostProcessTask {
|
||||
PostProcessTask(this.element, this.action);
|
||||
}
|
||||
|
||||
class ReadingFilesTask extends CompilerTask {
|
||||
ReadingFilesTask(Compiler compiler) : super(compiler);
|
||||
String get name => 'Reading input files';
|
||||
}
|
||||
|
||||
abstract class Backend {
|
||||
final Compiler compiler;
|
||||
final ConstantSystem constantSystem;
|
||||
@@ -253,7 +247,9 @@ abstract class Backend {
|
||||
|
||||
void registerStaticUse(Element element, Enqueuer enqueuer) {}
|
||||
|
||||
void onLibraryLoaded(LibraryElement library, Uri uri) {}
|
||||
Future onLibraryLoaded(LibraryElement library, Uri uri) {
|
||||
return new Future.value();
|
||||
}
|
||||
|
||||
void registerMetadataInstantiatedType(DartType type, TreeElements elements) {}
|
||||
void registerMetadataStaticUse(Element element) {}
|
||||
@@ -512,7 +508,6 @@ abstract class Compiler implements DiagnosticListener {
|
||||
ConstantHandler constantHandler;
|
||||
ConstantHandler metadataHandler;
|
||||
EnqueueTask enqueuer;
|
||||
CompilerTask fileReadingTask;
|
||||
DeferredLoadTask deferredLoadTask;
|
||||
MirrorUsageAnalyzerTask mirrorUsageAnalyzerTask;
|
||||
ContainerTracer containerTracer;
|
||||
@@ -614,7 +609,6 @@ abstract class Compiler implements DiagnosticListener {
|
||||
validator = new TreeValidatorTask(this);
|
||||
|
||||
tasks = [
|
||||
fileReadingTask = new ReadingFilesTask(this),
|
||||
libraryLoader = new LibraryLoaderTask(this),
|
||||
scanner = new ScannerTask(this),
|
||||
dietParser = new DietParserTask(this),
|
||||
@@ -731,14 +725,15 @@ abstract class Compiler implements DiagnosticListener {
|
||||
reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO);
|
||||
}
|
||||
|
||||
bool run(Uri uri) {
|
||||
Future<bool> run(Uri uri) {
|
||||
totalCompileTime.start();
|
||||
try {
|
||||
runCompiler(uri);
|
||||
} on CompilerCancelledException catch (exception) {
|
||||
log('Error: $exception');
|
||||
return false;
|
||||
} catch (exception) {
|
||||
|
||||
return new Future.sync(() => runCompiler(uri)).catchError((error) {
|
||||
if (error is CompilerCancelledException) {
|
||||
log('Error: $error');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!hasCrashed) {
|
||||
hasCrashed = true;
|
||||
@@ -750,12 +745,13 @@ abstract class Compiler implements DiagnosticListener {
|
||||
} catch (doubleFault) {
|
||||
// Ignoring exceptions in exception handling.
|
||||
}
|
||||
rethrow;
|
||||
} finally {
|
||||
throw error;
|
||||
}).whenComplete(() {
|
||||
tracer.close();
|
||||
totalCompileTime.stop();
|
||||
}
|
||||
return !compilationFailed;
|
||||
}).then((_) {
|
||||
return !compilationFailed;
|
||||
});
|
||||
}
|
||||
|
||||
bool hasIsolateSupport() => isolateLibrary != null;
|
||||
@@ -764,7 +760,7 @@ abstract class Compiler implements DiagnosticListener {
|
||||
* This method is called before [library] import and export scopes have been
|
||||
* set up.
|
||||
*/
|
||||
void onLibraryLoaded(LibraryElement library, Uri uri) {
|
||||
Future onLibraryLoaded(LibraryElement library, Uri uri) {
|
||||
if (dynamicClass != null) {
|
||||
// When loading the built-in libraries, dynamicClass is null. We
|
||||
// take advantage of this as core imports js_helper and sees [dynamic]
|
||||
@@ -791,12 +787,12 @@ abstract class Compiler implements DiagnosticListener {
|
||||
findRequiredElement(library, const SourceString('DeferredLibrary'));
|
||||
} else if (isolateHelperLibrary == null
|
||||
&& (uri == new Uri(scheme: 'dart', path: '_isolate_helper'))) {
|
||||
isolateHelperLibrary = scanBuiltinLibrary('_isolate_helper');
|
||||
isolateHelperLibrary = library;
|
||||
} else if (foreignLibrary == null
|
||||
&& (uri == new Uri(scheme: 'dart', path: '_foreign_helper'))) {
|
||||
foreignLibrary = scanBuiltinLibrary('_foreign_helper');
|
||||
foreignLibrary = library;
|
||||
}
|
||||
backend.onLibraryLoaded(library, uri);
|
||||
return backend.onLibraryLoaded(library, uri);
|
||||
}
|
||||
|
||||
Element findRequiredElement(LibraryElement library, SourceString name) {
|
||||
@@ -824,7 +820,7 @@ abstract class Compiler implements DiagnosticListener {
|
||||
}
|
||||
}
|
||||
|
||||
LibraryElement scanBuiltinLibrary(String filename);
|
||||
Future<LibraryElement> scanBuiltinLibrary(String filename);
|
||||
|
||||
void initializeSpecialClasses() {
|
||||
final List missingCoreClasses = [];
|
||||
@@ -902,26 +898,32 @@ abstract class Compiler implements DiagnosticListener {
|
||||
listClass.lookupConstructor(callConstructor);
|
||||
}
|
||||
|
||||
void scanBuiltinLibraries() {
|
||||
jsHelperLibrary = scanBuiltinLibrary('_js_helper');
|
||||
interceptorsLibrary = scanBuiltinLibrary('_interceptors');
|
||||
assertMethod = jsHelperLibrary.find(const SourceString('assertHelper'));
|
||||
identicalFunction = coreLibrary.find(const SourceString('identical'));
|
||||
Future scanBuiltinLibraries() {
|
||||
return scanBuiltinLibrary('_js_helper').then((LibraryElement library) {
|
||||
jsHelperLibrary = library;
|
||||
return scanBuiltinLibrary('_interceptors');
|
||||
}).then((LibraryElement library) {
|
||||
interceptorsLibrary = library;
|
||||
|
||||
initializeSpecialClasses();
|
||||
assertMethod = jsHelperLibrary.find(const SourceString('assertHelper'));
|
||||
identicalFunction = coreLibrary.find(const SourceString('identical'));
|
||||
|
||||
functionClass.ensureResolved(this);
|
||||
functionApplyMethod =
|
||||
functionClass.lookupLocalMember(const SourceString('apply'));
|
||||
jsInvocationMirrorClass.ensureResolved(this);
|
||||
invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON);
|
||||
initializeSpecialClasses();
|
||||
|
||||
if (preserveComments) {
|
||||
var uri = new Uri(scheme: 'dart', path: 'mirrors');
|
||||
LibraryElement libraryElement =
|
||||
libraryLoader.loadLibrary(uri, null, uri);
|
||||
documentClass = libraryElement.find(const SourceString('Comment'));
|
||||
}
|
||||
functionClass.ensureResolved(this);
|
||||
functionApplyMethod =
|
||||
functionClass.lookupLocalMember(const SourceString('apply'));
|
||||
jsInvocationMirrorClass.ensureResolved(this);
|
||||
invokeOnMethod = jsInvocationMirrorClass.lookupLocalMember(INVOKE_ON);
|
||||
|
||||
if (preserveComments) {
|
||||
var uri = new Uri(scheme: 'dart', path: 'mirrors');
|
||||
return libraryLoader.loadLibrary(uri, null, uri).then(
|
||||
(LibraryElement libraryElement) {
|
||||
documentClass = libraryElement.find(const SourceString('Comment'));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void importHelperLibrary(LibraryElement library) {
|
||||
@@ -936,28 +938,39 @@ abstract class Compiler implements DiagnosticListener {
|
||||
*/
|
||||
Uri resolvePatchUri(String dartLibraryPath);
|
||||
|
||||
void runCompiler(Uri uri) {
|
||||
Future runCompiler(Uri uri) {
|
||||
// TODO(ahe): This prevents memory leaks when invoking the compiler
|
||||
// multiple times. Implement a better mechanism where StringWrapper
|
||||
// instances are shared on a per library basis.
|
||||
SourceString.canonicalizedValues.clear();
|
||||
|
||||
assert(uri != null || analyzeOnly);
|
||||
scanBuiltinLibraries();
|
||||
if (librariesToAnalyzeWhenRun != null) {
|
||||
for (Uri libraryUri in librariesToAnalyzeWhenRun) {
|
||||
log('analyzing $libraryUri ($buildId)');
|
||||
libraryLoader.loadLibrary(libraryUri, null, libraryUri);
|
||||
return scanBuiltinLibraries().then((_) {
|
||||
if (librariesToAnalyzeWhenRun != null) {
|
||||
return Future.forEach(librariesToAnalyzeWhenRun, (libraryUri) {
|
||||
log('analyzing $libraryUri ($buildId)');
|
||||
return libraryLoader.loadLibrary(libraryUri, null, libraryUri);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (uri != null) {
|
||||
if (analyzeOnly) {
|
||||
log('analyzing $uri ($buildId)');
|
||||
} else {
|
||||
log('compiling $uri ($buildId)');
|
||||
}).then((_) {
|
||||
if (uri != null) {
|
||||
if (analyzeOnly) {
|
||||
log('analyzing $uri ($buildId)');
|
||||
} else {
|
||||
log('compiling $uri ($buildId)');
|
||||
}
|
||||
return libraryLoader.loadLibrary(uri, null, uri)
|
||||
.then((LibraryElement library) {
|
||||
mainApp = library;
|
||||
});
|
||||
}
|
||||
mainApp = libraryLoader.loadLibrary(uri, null, uri);
|
||||
}
|
||||
}).then((_) {
|
||||
compileLoadedLibraries();
|
||||
});
|
||||
}
|
||||
|
||||
/// Performs the compilation when all libraries have been loaded.
|
||||
void compileLoadedLibraries() {
|
||||
Element main = null;
|
||||
if (mainApp != null) {
|
||||
main = mainApp.find(MAIN);
|
||||
@@ -973,8 +986,8 @@ abstract class Compiler implements DiagnosticListener {
|
||||
mainApp,
|
||||
MessageKind.GENERIC,
|
||||
{'text': 'Error: Could not find "${MAIN.slowToString()}". '
|
||||
'No source will be analyzed. '
|
||||
'Use "--analyze-all" to analyze all code in the library.'});
|
||||
'No source will be analyzed. '
|
||||
'Use "--analyze-all" to analyze all code in the library.'});
|
||||
}
|
||||
} else {
|
||||
if (!main.isFunction()) {
|
||||
@@ -990,7 +1003,7 @@ abstract class Compiler implements DiagnosticListener {
|
||||
parameter,
|
||||
MessageKind.GENERIC,
|
||||
{'text':
|
||||
'Error: "${MAIN.slowToString()}" cannot have parameters.'});
|
||||
'Error: "${MAIN.slowToString()}" cannot have parameters.'});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1046,7 +1059,8 @@ abstract class Compiler implements DiagnosticListener {
|
||||
backend.enableNoSuchMethod(enqueuer.codegen);
|
||||
}
|
||||
if (compileAll) {
|
||||
libraries.forEach((_, lib) => fullyEnqueueLibrary(lib, enqueuer.codegen));
|
||||
libraries.forEach((_, lib) => fullyEnqueueLibrary(lib,
|
||||
enqueuer.codegen));
|
||||
}
|
||||
processQueue(enqueuer.codegen, main);
|
||||
enqueuer.codegen.logSummary(log);
|
||||
@@ -1373,7 +1387,7 @@ abstract class Compiler implements DiagnosticListener {
|
||||
*
|
||||
* See [LibraryLoader] for terminology on URIs.
|
||||
*/
|
||||
Script readScript(Uri readableUri, [Node node]) {
|
||||
Future<Script> readScript(Uri readableUri, [Element element, Node node]) {
|
||||
unimplemented('Compiler.readScript');
|
||||
}
|
||||
|
||||
@@ -1517,10 +1531,14 @@ class SourceSpan {
|
||||
bool invariant(Spannable spannable, var condition, {var message: null}) {
|
||||
// TODO(johnniwinther): Use [spannable] and [message] to provide better
|
||||
// information on assertion errors.
|
||||
if (spannable == null) {
|
||||
throw new SpannableAssertionFailure(CURRENT_ELEMENT_SPANNABLE,
|
||||
"Spannable was null for invariant. Use CURRENT_ELEMENT_SPANNABLE.");
|
||||
}
|
||||
if (condition is Function){
|
||||
condition = condition();
|
||||
}
|
||||
if (spannable == null || !condition) {
|
||||
if (!condition) {
|
||||
if (message is Function) {
|
||||
message = message();
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ void parseCommandLine(List<OptionHandler> handlers, List<String> argv) {
|
||||
}
|
||||
}
|
||||
|
||||
void compile(List<String> argv) {
|
||||
Future compile(List<String> argv) {
|
||||
bool isWindows = (Platform.operatingSystem == 'windows');
|
||||
stackTraceFilePrefix = '$currentDirectory';
|
||||
Uri libraryRoot = currentDirectory;
|
||||
@@ -105,6 +105,7 @@ void compile(List<String> argv) {
|
||||
String outputLanguage = 'JavaScript';
|
||||
bool stripArgumentSet = false;
|
||||
bool analyzeOnly = false;
|
||||
// TODO(johnniwinther): Measure time for reading files.
|
||||
SourceFileProvider inputProvider = new SourceFileProvider();
|
||||
FormattingDiagnosticHandler diagnosticHandler =
|
||||
new FormattingDiagnosticHandler(inputProvider);
|
||||
@@ -287,11 +288,6 @@ void compile(List<String> argv) {
|
||||
helpAndFail('Error: Extra arguments: ${extra.join(" ")}');
|
||||
}
|
||||
|
||||
void handler(Uri uri, int begin, int end, String message,
|
||||
api.Diagnostic kind) {
|
||||
diagnosticHandler.diagnosticHandler(uri, begin, end, message, kind);
|
||||
}
|
||||
|
||||
Uri uri = currentDirectory.resolve(arguments[0]);
|
||||
if (packageRoot == null) {
|
||||
packageRoot = uri.resolve('./packages/');
|
||||
@@ -386,10 +382,10 @@ void compile(List<String> argv) {
|
||||
return new EventSinkWrapper(writeStringSync, onDone);
|
||||
}
|
||||
|
||||
api.compile(uri, libraryRoot, packageRoot,
|
||||
inputProvider.readStringFromUri, handler,
|
||||
return api.compile(uri, libraryRoot, packageRoot,
|
||||
inputProvider, diagnosticHandler,
|
||||
options, outputProvider)
|
||||
.then(compilationDone);
|
||||
.then(compilationDone);
|
||||
}
|
||||
|
||||
class EventSinkWrapper extends EventSink<String> {
|
||||
@@ -424,11 +420,11 @@ void fail(String message) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void compilerMain(Options options) {
|
||||
Future compilerMain(Options options) {
|
||||
var root = uriPathToNative("/$LIBRARY_ROOT");
|
||||
List<String> argv = ['--library-root=${options.script}$root'];
|
||||
argv.addAll(options.arguments);
|
||||
compile(argv);
|
||||
return compile(argv);
|
||||
}
|
||||
|
||||
void help() {
|
||||
@@ -566,20 +562,22 @@ void helpAndFail(String message) {
|
||||
}
|
||||
|
||||
void mainWithErrorHandler(Options options) {
|
||||
try {
|
||||
compilerMain(options);
|
||||
} catch (exception, trace) {
|
||||
new Future.sync(() => compilerMain(options)).catchError((exception) {
|
||||
try {
|
||||
print('Internal error: $exception');
|
||||
} catch (ignored) {
|
||||
print('Internal error: error while printing exception');
|
||||
}
|
||||
|
||||
try {
|
||||
print(trace);
|
||||
var trace = getAttachedStackTrace(exception);
|
||||
if (trace != null) {
|
||||
print(trace);
|
||||
}
|
||||
} finally {
|
||||
exit(253); // 253 is recognized as a crash by our test scripts.
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -505,15 +505,19 @@ class DartBackend extends Backend {
|
||||
|
||||
log(String message) => compiler.log('[DartBackend] $message');
|
||||
|
||||
void onLibraryLoaded(LibraryElement library, Uri uri) {
|
||||
Future onLibraryLoaded(LibraryElement library, Uri uri) {
|
||||
if (useMirrorHelperLibrary && library == compiler.mirrorsLibrary) {
|
||||
mirrorHelperLibrary = compiler.scanBuiltinLibrary(
|
||||
MirrorRenamer.MIRROR_HELPER_LIBRARY_NAME);
|
||||
mirrorHelperGetNameFunction = mirrorHelperLibrary.find(
|
||||
const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION));
|
||||
mirrorHelperSymbolsMap = mirrorHelperLibrary.find(
|
||||
const SourceString(MirrorRenamer.MIRROR_HELPER_SYMBOLS_MAP_NAME));
|
||||
return compiler.scanBuiltinLibrary(
|
||||
MirrorRenamer.MIRROR_HELPER_LIBRARY_NAME).
|
||||
then((LibraryElement element) {
|
||||
mirrorHelperLibrary = element;
|
||||
mirrorHelperGetNameFunction = mirrorHelperLibrary.find(
|
||||
const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION));
|
||||
mirrorHelperSymbolsMap = mirrorHelperLibrary.find(
|
||||
const SourceString(MirrorRenamer.MIRROR_HELPER_SYMBOLS_MAP_NAME));
|
||||
});
|
||||
}
|
||||
return new Future.value();
|
||||
}
|
||||
|
||||
void registerStaticSend(Element element, Node node) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
library dart_backend;
|
||||
|
||||
import 'dart:async' show Future;
|
||||
import '../elements/elements.dart';
|
||||
import '../elements/modelx.dart' show SynthesizedConstructorElementX;
|
||||
import '../dart2jslib.dart';
|
||||
|
||||
@@ -47,8 +47,6 @@ class DeferredLoadTask extends CompilerTask {
|
||||
/// should become obsolete.
|
||||
final Set<Element> allDeferredElements = new LinkedHashSet<Element>();
|
||||
|
||||
ClassElement cachedDeferredLibraryClass;
|
||||
|
||||
DeferredLoadTask(Compiler compiler) : super(compiler);
|
||||
|
||||
String get name => 'Deferred Loading';
|
||||
|
||||
@@ -1490,7 +1490,7 @@ class JavaScriptBackend extends Backend {
|
||||
return false;
|
||||
}
|
||||
|
||||
void onLibraryLoaded(LibraryElement library, Uri uri) {
|
||||
Future onLibraryLoaded(LibraryElement library, Uri uri) {
|
||||
if (uri == Uri.parse('dart:_js_mirrors')) {
|
||||
disableTreeShakingMarker =
|
||||
library.find(const SourceString('disableTreeShaking'));
|
||||
@@ -1500,6 +1500,7 @@ class JavaScriptBackend extends Backend {
|
||||
preserveNamesMarker =
|
||||
library.find(const SourceString('preserveNames'));
|
||||
}
|
||||
return new Future.value();
|
||||
}
|
||||
|
||||
void registerMetadataInstantiatedType(DartType type, TreeElements elements) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
library js_backend;
|
||||
|
||||
import 'dart:async' show Future;
|
||||
import 'dart:collection' show LinkedHashMap, Queue;
|
||||
|
||||
import '../closure.dart';
|
||||
|
||||
@@ -113,12 +113,13 @@ abstract class LibraryLoader extends CompilerTask {
|
||||
*/
|
||||
// TODO(johnniwinther): Remove [canonicalUri] together with
|
||||
// [Compiler.scanBuiltinLibrary].
|
||||
LibraryElement loadLibrary(Uri resolvedUri, Node node, Uri canonicalUri);
|
||||
Future<LibraryElement> loadLibrary(Uri resolvedUri, Node node,
|
||||
Uri canonicalUri);
|
||||
|
||||
// TODO(johnniwinther): Remove this when patches don't need special parsing.
|
||||
void registerLibraryFromTag(LibraryDependencyHandler handler,
|
||||
LibraryElement library,
|
||||
LibraryDependency tag);
|
||||
Future registerLibraryFromTag(LibraryDependencyHandler handler,
|
||||
LibraryElement library,
|
||||
LibraryDependency tag);
|
||||
|
||||
/**
|
||||
* Adds the elements in the export scope of [importedLibrary] to the import
|
||||
@@ -227,18 +228,25 @@ class LibraryLoaderTask extends LibraryLoader {
|
||||
|
||||
LibraryDependencyHandler currentHandler;
|
||||
|
||||
LibraryElement loadLibrary(Uri resolvedUri, Node node, Uri canonicalUri) {
|
||||
Future<LibraryElement> loadLibrary(Uri resolvedUri, Node node,
|
||||
Uri canonicalUri) {
|
||||
return measure(() {
|
||||
assert(currentHandler == null);
|
||||
// TODO(johnniwinther): Ensure that currentHandler correctly encloses the
|
||||
// loading of a library cluster.
|
||||
currentHandler = new LibraryDependencyHandler(compiler);
|
||||
LibraryElement library =
|
||||
createLibrary(currentHandler, null, resolvedUri, node, canonicalUri);
|
||||
currentHandler.computeExports();
|
||||
currentHandler = null;
|
||||
var workList = onLibraryLoadedCallbacks;
|
||||
onLibraryLoadedCallbacks = [];
|
||||
workList.forEach((f) => f());
|
||||
return library;
|
||||
return createLibrary(currentHandler, null, resolvedUri, node,
|
||||
canonicalUri).then((LibraryElement library) {
|
||||
return compiler.withCurrentElement(library, () {
|
||||
return measure(() {
|
||||
currentHandler.computeExports();
|
||||
currentHandler = null;
|
||||
var workList = onLibraryLoadedCallbacks;
|
||||
onLibraryLoadedCallbacks = [];
|
||||
return Future.forEach(workList, (f) => f()).then((_) => library);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -248,8 +256,8 @@ class LibraryLoaderTask extends LibraryLoader {
|
||||
* The imported/exported libraries are loaded and processed recursively but
|
||||
* the import/export scopes are not set up.
|
||||
*/
|
||||
void processLibraryTags(LibraryDependencyHandler handler,
|
||||
LibraryElement library) {
|
||||
Future processLibraryTags(LibraryDependencyHandler handler,
|
||||
LibraryElement library) {
|
||||
int tagState = TagState.NO_TAG_SEEN;
|
||||
|
||||
/**
|
||||
@@ -270,49 +278,62 @@ class LibraryLoaderTask extends LibraryLoader {
|
||||
bool importsDartCore = false;
|
||||
var libraryDependencies = new LinkBuilder<LibraryDependency>();
|
||||
Uri base = library.entryCompilationUnit.script.uri;
|
||||
for (LibraryTag tag in library.tags.reverse()) {
|
||||
if (tag.isImport) {
|
||||
Import import = tag;
|
||||
tagState = checkTag(TagState.IMPORT_OR_EXPORT, import);
|
||||
if (import.uri.dartString.slowToString() == 'dart:core') {
|
||||
importsDartCore = true;
|
||||
}
|
||||
libraryDependencies.addLast(import);
|
||||
} else if (tag.isExport) {
|
||||
tagState = checkTag(TagState.IMPORT_OR_EXPORT, tag);
|
||||
libraryDependencies.addLast(tag);
|
||||
} else if (tag.isLibraryName) {
|
||||
tagState = checkTag(TagState.LIBRARY, tag);
|
||||
if (library.libraryTag != null) {
|
||||
compiler.cancel("duplicated library declaration", node: tag);
|
||||
|
||||
// TODO(rnystrom): Remove .toList() here if #11523 is fixed.
|
||||
return Future.forEach(library.tags.reverse().toList(), (LibraryTag tag) {
|
||||
compiler.withCurrentElement(library, () {
|
||||
if (tag.isImport) {
|
||||
Import import = tag;
|
||||
tagState = checkTag(TagState.IMPORT_OR_EXPORT, import);
|
||||
if (import.uri.dartString.slowToString() == 'dart:core') {
|
||||
importsDartCore = true;
|
||||
}
|
||||
libraryDependencies.addLast(import);
|
||||
} else if (tag.isExport) {
|
||||
tagState = checkTag(TagState.IMPORT_OR_EXPORT, tag);
|
||||
libraryDependencies.addLast(tag);
|
||||
} else if (tag.isLibraryName) {
|
||||
tagState = checkTag(TagState.LIBRARY, tag);
|
||||
if (library.libraryTag != null) {
|
||||
compiler.cancel("duplicated library declaration", node: tag);
|
||||
} else {
|
||||
library.libraryTag = tag;
|
||||
}
|
||||
checkDuplicatedLibraryName(library);
|
||||
} else if (tag.isPart) {
|
||||
Part part = tag;
|
||||
StringNode uri = part.uri;
|
||||
Uri resolvedUri = base.resolve(uri.dartString.slowToString());
|
||||
tagState = checkTag(TagState.SOURCE, part);
|
||||
return scanPart(part, resolvedUri, library);
|
||||
} else {
|
||||
library.libraryTag = tag;
|
||||
compiler.internalError("Unhandled library tag.", node: tag);
|
||||
}
|
||||
checkDuplicatedLibraryName(library);
|
||||
} else if (tag.isPart) {
|
||||
Part part = tag;
|
||||
StringNode uri = part.uri;
|
||||
Uri resolvedUri = base.resolve(uri.dartString.slowToString());
|
||||
tagState = checkTag(TagState.SOURCE, part);
|
||||
scanPart(part, resolvedUri, library);
|
||||
} else {
|
||||
compiler.internalError("Unhandled library tag.", node: tag);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply patch, if any.
|
||||
if (library.isPlatformLibrary) {
|
||||
patchDartLibrary(handler, library, library.canonicalUri.path);
|
||||
}
|
||||
|
||||
// Import dart:core if not already imported.
|
||||
if (!importsDartCore && !isDartCore(library.canonicalUri)) {
|
||||
handler.registerDependency(library, null, loadCoreLibrary(handler));
|
||||
}
|
||||
|
||||
for (LibraryDependency tag in libraryDependencies.toLink()) {
|
||||
registerLibraryFromTag(handler, library, tag);
|
||||
}
|
||||
});
|
||||
}).then((_) {
|
||||
return compiler.withCurrentElement(library, () {
|
||||
// Apply patch, if any.
|
||||
if (library.isPlatformLibrary) {
|
||||
return patchDartLibrary(handler, library, library.canonicalUri.path);
|
||||
}
|
||||
});
|
||||
}).then((_) {
|
||||
return compiler.withCurrentElement(library, () {
|
||||
// Import dart:core if not already imported.
|
||||
if (!importsDartCore && !isDartCore(library.canonicalUri)) {
|
||||
return loadCoreLibrary(handler).then((LibraryElement coreLibrary) {
|
||||
handler.registerDependency(library, null, coreLibrary);
|
||||
});
|
||||
}
|
||||
});
|
||||
}).then((_) {
|
||||
// TODO(rnystrom): Remove .toList() here if #11523 is fixed.
|
||||
return Future.forEach(libraryDependencies.toLink().toList(), (tag) {
|
||||
return compiler.withCurrentElement(library, () {
|
||||
return registerLibraryFromTag(handler, library, tag);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void checkDuplicatedLibraryName(LibraryElement library) {
|
||||
@@ -341,42 +362,48 @@ class LibraryLoaderTask extends LibraryLoader {
|
||||
/**
|
||||
* Lazily loads and returns the [LibraryElement] for the dart:core library.
|
||||
*/
|
||||
LibraryElement loadCoreLibrary(LibraryDependencyHandler handler) {
|
||||
if (compiler.coreLibrary == null) {
|
||||
Uri coreUri = new Uri(scheme: 'dart', path: 'core');
|
||||
compiler.coreLibrary
|
||||
= createLibrary(handler, null, coreUri, null, coreUri);
|
||||
Future<LibraryElement> loadCoreLibrary(LibraryDependencyHandler handler) {
|
||||
if (compiler.coreLibrary != null) {
|
||||
return new Future.value(compiler.coreLibrary);
|
||||
}
|
||||
return compiler.coreLibrary;
|
||||
|
||||
Uri coreUri = new Uri(scheme: 'dart', path: 'core');
|
||||
return createLibrary(handler, null, coreUri, null, coreUri)
|
||||
.then((LibraryElement library) {
|
||||
compiler.coreLibrary = library;
|
||||
return library;
|
||||
});
|
||||
}
|
||||
|
||||
void patchDartLibrary(LibraryDependencyHandler handler,
|
||||
Future patchDartLibrary(LibraryDependencyHandler handler,
|
||||
LibraryElement library, String dartLibraryPath) {
|
||||
if (library.isPatched) return;
|
||||
if (library.isPatched) return new Future.value();
|
||||
Uri patchUri = compiler.resolvePatchUri(dartLibraryPath);
|
||||
if (patchUri != null) {
|
||||
compiler.patchParser.patchLibrary(handler, patchUri, library);
|
||||
}
|
||||
if (patchUri == null) return new Future.value();
|
||||
|
||||
return compiler.patchParser.patchLibrary(handler, patchUri, library);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a part tag in the scope of [library]. The [resolvedUri] given is
|
||||
* used as is, any URI resolution should be done beforehand.
|
||||
*/
|
||||
void scanPart(Part part, Uri resolvedUri, LibraryElement library) {
|
||||
Future scanPart(Part part, Uri resolvedUri, LibraryElement library) {
|
||||
if (!resolvedUri.isAbsolute) throw new ArgumentError(resolvedUri);
|
||||
Uri readableUri = compiler.translateResolvedUri(library, resolvedUri, part);
|
||||
if (readableUri == null) return;
|
||||
Script sourceScript = compiler.readScript(readableUri, part);
|
||||
if (sourceScript == null) return;
|
||||
CompilationUnitElement unit =
|
||||
new CompilationUnitElementX(sourceScript, library);
|
||||
compiler.withCurrentElement(unit, () {
|
||||
compiler.scanner.scan(unit);
|
||||
if (unit.partTag == null) {
|
||||
compiler.reportError(unit, MessageKind.MISSING_PART_OF_TAG);
|
||||
}
|
||||
});
|
||||
if (readableUri == null) return new Future.value();
|
||||
return compiler.readScript(readableUri, library, part).
|
||||
then((Script sourceScript) {
|
||||
if (sourceScript == null) return;
|
||||
CompilationUnitElement unit =
|
||||
new CompilationUnitElementX(sourceScript, library);
|
||||
compiler.withCurrentElement(unit, () {
|
||||
compiler.scanner.scan(unit);
|
||||
if (unit.partTag == null) {
|
||||
compiler.reportError(unit, MessageKind.MISSING_PART_OF_TAG);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,25 +411,27 @@ class LibraryLoaderTask extends LibraryLoader {
|
||||
* registering its dependency in [handler] for the computation of the import/
|
||||
* export scope.
|
||||
*/
|
||||
void registerLibraryFromTag(LibraryDependencyHandler handler,
|
||||
LibraryElement library,
|
||||
LibraryDependency tag) {
|
||||
Future registerLibraryFromTag(LibraryDependencyHandler handler,
|
||||
LibraryElement library,
|
||||
LibraryDependency tag) {
|
||||
Uri base = library.entryCompilationUnit.script.uri;
|
||||
Uri resolvedUri = base.resolve(tag.uri.dartString.slowToString());
|
||||
LibraryElement loadedLibrary =
|
||||
createLibrary(handler, library, resolvedUri, tag.uri, resolvedUri);
|
||||
if (loadedLibrary == null) return;
|
||||
handler.registerDependency(library, tag, loadedLibrary);
|
||||
return createLibrary(handler, library, resolvedUri, tag.uri, resolvedUri)
|
||||
.then((LibraryElement loadedLibrary) {
|
||||
if (loadedLibrary == null) return;
|
||||
compiler.withCurrentElement(library, () {
|
||||
handler.registerDependency(library, tag, loadedLibrary);
|
||||
|
||||
if (!loadedLibrary.hasLibraryName()) {
|
||||
compiler.withCurrentElement(library, () {
|
||||
compiler.reportFatalError(
|
||||
tag == null ? null : tag.uri,
|
||||
MessageKind.GENERIC,
|
||||
{'text':
|
||||
'Error: No library name found in ${loadedLibrary.canonicalUri}.'});
|
||||
});
|
||||
}
|
||||
if (!loadedLibrary.hasLibraryName()) {
|
||||
compiler.reportFatalError(
|
||||
tag == null ? null : tag.uri,
|
||||
MessageKind.GENERIC,
|
||||
{'text':
|
||||
'Error: No library name found in '
|
||||
'${loadedLibrary.canonicalUri}.'});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,38 +442,42 @@ class LibraryLoaderTask extends LibraryLoader {
|
||||
*/
|
||||
// TODO(johnniwinther): Remove [canonicalUri] and make [resolvedUri] the
|
||||
// canonical uri when [Compiler.scanBuiltinLibrary] is removed.
|
||||
LibraryElement createLibrary(LibraryDependencyHandler handler,
|
||||
Future<LibraryElement> createLibrary(LibraryDependencyHandler handler,
|
||||
LibraryElement importingLibrary,
|
||||
Uri resolvedUri, Node node, Uri canonicalUri) {
|
||||
// TODO(johnniwinther): Create erroneous library elements for missing
|
||||
// libraries.
|
||||
Uri readableUri =
|
||||
compiler.translateResolvedUri(importingLibrary, resolvedUri, node);
|
||||
if (readableUri == null) return null;
|
||||
if (readableUri == null) return new Future.value();
|
||||
LibraryElement library;
|
||||
if (canonicalUri != null) {
|
||||
library = compiler.libraries[canonicalUri.toString()];
|
||||
}
|
||||
if (library == null) {
|
||||
Script script = compiler.readScript(readableUri, node);
|
||||
if (script == null) return null;
|
||||
|
||||
library = new LibraryElementX(script, canonicalUri);
|
||||
handler.registerNewLibrary(library);
|
||||
native.maybeEnableNative(compiler, library);
|
||||
if (canonicalUri != null) {
|
||||
compiler.libraries[canonicalUri.toString()] = library;
|
||||
}
|
||||
|
||||
compiler.withCurrentElement(library, () {
|
||||
compiler.scanner.scanLibrary(library);
|
||||
processLibraryTags(handler, library);
|
||||
handler.registerLibraryExports(library);
|
||||
onLibraryLoadedCallbacks.add(
|
||||
() => compiler.onLibraryLoaded(library, resolvedUri));
|
||||
});
|
||||
if (library != null) {
|
||||
return new Future.value(library);
|
||||
}
|
||||
return library;
|
||||
return compiler.readScript(readableUri, importingLibrary, node)
|
||||
.then((Script script) {
|
||||
if (script == null) return null;
|
||||
LibraryElement element = new LibraryElementX(script, canonicalUri);
|
||||
compiler.withCurrentElement(element, () {
|
||||
handler.registerNewLibrary(element);
|
||||
native.maybeEnableNative(compiler, element);
|
||||
if (canonicalUri != null) {
|
||||
compiler.libraries[canonicalUri.toString()] = element;
|
||||
}
|
||||
compiler.scanner.scanLibrary(element);
|
||||
});
|
||||
return processLibraryTags(handler, element).then((_) {
|
||||
compiler.withCurrentElement(element, () {
|
||||
handler.registerLibraryExports(element);
|
||||
onLibraryLoadedCallbacks.add(
|
||||
() => compiler.onLibraryLoaded(element, resolvedUri));
|
||||
});
|
||||
return element;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// TODO(johnniwinther): Remove this method when 'js_helper' is handled by
|
||||
|
||||
@@ -227,12 +227,13 @@ Future<MirrorSystem> analyze(List<Uri> libraries,
|
||||
internalDiagnosticHandler,
|
||||
libraryRoot, packageRoot, options);
|
||||
compiler.librariesToAnalyzeWhenRun = libraries;
|
||||
bool success = compiler.run(null);
|
||||
if (success && !compilationFailed) {
|
||||
return new Future<MirrorSystem>.value(new Dart2JsMirrorSystem(compiler));
|
||||
} else {
|
||||
return new Future<MirrorSystem>.error('Failed to create mirror system.');
|
||||
}
|
||||
return compiler.run(null).then((bool success) {
|
||||
if (success && !compilationFailed) {
|
||||
return new Dart2JsMirrorSystem(compiler);
|
||||
} else {
|
||||
throw new StateError('Failed to create mirror system.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -382,7 +383,7 @@ abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror {
|
||||
// Lookup [: prefix.id :].
|
||||
String prefix = name.substring(0, index);
|
||||
String id = name.substring(index+1);
|
||||
result = scope.lookup(new SourceString(prefix));
|
||||
result = scope.lookup(new SourceString(prefix));
|
||||
if (result != null && result.isPrefix()) {
|
||||
PrefixElement prefix = result;
|
||||
result = prefix.lookupLocalMember(new SourceString(id));
|
||||
|
||||
@@ -114,6 +114,8 @@
|
||||
|
||||
library patchparser;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import "tree/tree.dart" as tree;
|
||||
import "dart2jslib.dart" as leg; // CompilerTask, Compiler.
|
||||
import "../compiler.dart" as api;
|
||||
@@ -131,28 +133,31 @@ class PatchParserTask extends leg.CompilerTask {
|
||||
* injections to the library, and returns a list of class
|
||||
* patches.
|
||||
*/
|
||||
void patchLibrary(leg.LibraryDependencyHandler handler,
|
||||
Future patchLibrary(leg.LibraryDependencyHandler handler,
|
||||
Uri patchUri, LibraryElement originLibrary) {
|
||||
|
||||
leg.Script script = compiler.readScript(patchUri, null);
|
||||
var patchLibrary = new LibraryElementX(script, null, originLibrary);
|
||||
compiler.withCurrentElement(patchLibrary, () {
|
||||
handler.registerNewLibrary(patchLibrary);
|
||||
LinkBuilder<tree.LibraryTag> imports = new LinkBuilder<tree.LibraryTag>();
|
||||
compiler.withCurrentElement(patchLibrary.entryCompilationUnit, () {
|
||||
// This patches the elements of the patch library into [library].
|
||||
// Injected elements are added directly under the compilation unit.
|
||||
// Patch elements are stored on the patched functions or classes.
|
||||
scanLibraryElements(patchLibrary.entryCompilationUnit, imports);
|
||||
return compiler.readScript(patchUri, null).then((leg.Script script) {
|
||||
var patchLibrary = new LibraryElementX(script, null, originLibrary);
|
||||
return compiler.withCurrentElement(patchLibrary, () {
|
||||
handler.registerNewLibrary(patchLibrary);
|
||||
var imports = new LinkBuilder<tree.LibraryTag>();
|
||||
compiler.withCurrentElement(patchLibrary.entryCompilationUnit, () {
|
||||
// This patches the elements of the patch library into [library].
|
||||
// Injected elements are added directly under the compilation unit.
|
||||
// Patch elements are stored on the patched functions or classes.
|
||||
scanLibraryElements(patchLibrary.entryCompilationUnit, imports);
|
||||
});
|
||||
// After scanning declarations, we handle the import tags in the patch.
|
||||
// TODO(lrn): These imports end up in the original library and are in
|
||||
// scope for the original methods too. This should be fixed.
|
||||
compiler.importHelperLibrary(originLibrary);
|
||||
// TODO(rnystrom): Remove .toList() here if #11523 is fixed.
|
||||
return Future.forEach(imports.toLink().toList(), (tag) {
|
||||
return compiler.withCurrentElement(patchLibrary, () {
|
||||
return compiler.libraryLoader.registerLibraryFromTag(
|
||||
handler, patchLibrary, tag);
|
||||
});
|
||||
});
|
||||
});
|
||||
// After scanning declarations, we handle the import tags in the patch.
|
||||
// TODO(lrn): These imports end up in the original library and are in
|
||||
// scope for the original methods too. This should be fixed.
|
||||
compiler.importHelperLibrary(originLibrary);
|
||||
for (tree.LibraryTag tag in imports.toLink()) {
|
||||
compiler.libraryLoader.registerLibraryFromTag(
|
||||
handler, patchLibrary, tag);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,9 @@ class SourceFileProvider {
|
||||
try {
|
||||
source = readAll(uriPathToNative(resourceUri.path));
|
||||
} on FileException catch (ex) {
|
||||
throw "Error reading '${relativize(cwd, resourceUri, isWindows)}' "
|
||||
"(${ex.osError})";
|
||||
return new Future.error(
|
||||
"Error reading '${relativize(cwd, resourceUri, isWindows)}' "
|
||||
"(${ex.osError})");
|
||||
}
|
||||
dartCharactersRead += source.length;
|
||||
sourceFiles[resourceUri.toString()] = new SourceFile(
|
||||
|
||||
@@ -35,7 +35,7 @@ class SpannableAssertionFailure {
|
||||
final String message;
|
||||
SpannableAssertionFailure(this.node, this.message);
|
||||
|
||||
String toString() => 'Compiler crashed: $message.';
|
||||
String toString() => 'Compiler crashed: $message';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -125,6 +125,8 @@ class Runner {
|
||||
|
||||
String init() {
|
||||
Stopwatch sw = new Stopwatch()..start();
|
||||
// TODO(rnystrom): This is broken now that scanBuiltInLibraries is async.
|
||||
// Delete this sample.
|
||||
compiler.scanBuiltinLibraries();
|
||||
sw.stop();
|
||||
return 'Scanned core libraries in ${sw.elapsedMilliseconds}ms';
|
||||
@@ -221,10 +223,14 @@ class LeapCompiler extends Compiler {
|
||||
|
||||
String get legDirectory => libDir;
|
||||
|
||||
// TODO(rnystrom): This is broken now that scanBuiltInLibraries is async.
|
||||
// Delete this sample.
|
||||
LibraryElement scanBuiltinLibrary(String path) {
|
||||
Uri base = Uri.parse(html.window.location.toString());
|
||||
Uri libraryRoot = base.resolve(libDir);
|
||||
Uri resolved = libraryRoot.resolve(DART2JS_LIBRARY_MAP[path]);
|
||||
// TODO(rnystrom): This is broken now that scanBuiltInLibraries is async.
|
||||
// Delete this sample.
|
||||
LibraryElement library = scanner.loadLibrary(resolved, null);
|
||||
return library;
|
||||
}
|
||||
@@ -237,6 +243,8 @@ class LeapCompiler extends Compiler {
|
||||
return compilationUnit.script;
|
||||
}
|
||||
|
||||
// TODO(rnystrom): This is broken now that scanBuiltInLibraries is async.
|
||||
// Delete this sample.
|
||||
Script readScript(Uri uri, [ScriptTag node]) {
|
||||
String text = "";
|
||||
try {
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import "compiler_helper.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
const String SOURCE = """
|
||||
class Foo {
|
||||
@@ -28,24 +29,29 @@ main() {
|
||||
|
||||
main() {
|
||||
Uri uri = Uri.parse('test:code');
|
||||
var compiler = compilerFor(SOURCE, uri, analyzeAll: false);
|
||||
compiler.runCompiler(uri);
|
||||
Expect.isFalse(compiler.compilationFailed);
|
||||
print(compiler.warnings);
|
||||
Expect.isTrue(compiler.warnings.isEmpty, 'unexpected warnings');
|
||||
Expect.isTrue(compiler.errors.isEmpty, 'unexpected errors');
|
||||
compiler = compilerFor(SOURCE, uri, analyzeAll: true);
|
||||
compiler.runCompiler(uri);
|
||||
Expect.isTrue(compiler.compilationFailed);
|
||||
Expect.isTrue(compiler.warnings.isEmpty, 'unexpected warnings');
|
||||
Expect.equals(2, compiler.errors.length,
|
||||
'expected exactly two errors, but got ${compiler.errors}');
|
||||
asyncStart();
|
||||
var compiler1 = compilerFor(SOURCE, uri, analyzeAll: false);
|
||||
compiler1.runCompiler(uri).then((_) {
|
||||
Expect.isFalse(compiler1.compilationFailed);
|
||||
print(compiler1.warnings);
|
||||
Expect.isTrue(compiler1.warnings.isEmpty, 'unexpected warnings');
|
||||
Expect.isTrue(compiler1.errors.isEmpty, 'unexpected errors');
|
||||
}).whenComplete(() => asyncEnd());
|
||||
|
||||
Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST,
|
||||
compiler.errors[0].message.kind);
|
||||
Expect.equals("Foo", compiler.errors[0].node.toString());
|
||||
asyncStart();
|
||||
var compiler2 = compilerFor(SOURCE, uri, analyzeAll: true);
|
||||
compiler2.runCompiler(uri).then((_) {
|
||||
Expect.isTrue(compiler2.compilationFailed);
|
||||
Expect.isTrue(compiler2.warnings.isEmpty, 'unexpected warnings');
|
||||
Expect.equals(2, compiler2.errors.length,
|
||||
'expected exactly two errors, but got ${compiler2.errors}');
|
||||
|
||||
Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST,
|
||||
compiler.errors[1].message.kind);
|
||||
Expect.equals("Foo", compiler.errors[1].node.toString());
|
||||
Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST,
|
||||
compiler2.errors[0].message.kind);
|
||||
Expect.equals("Foo", compiler2.errors[0].node.toString());
|
||||
|
||||
Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST,
|
||||
compiler2.errors[1].message.kind);
|
||||
Expect.equals("Foo", compiler2.errors[1].node.toString());
|
||||
}).whenComplete(() => asyncEnd());
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ library analyze_api;
|
||||
|
||||
import '../../../sdk/lib/_internal/libraries.dart';
|
||||
import 'analyze_helper.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
/**
|
||||
* Map of white-listed warnings and errors.
|
||||
@@ -28,5 +29,5 @@ void main() {
|
||||
uriList.add(new Uri(scheme: 'dart', path: name));
|
||||
}
|
||||
});
|
||||
analyze(uriList, WHITE_LIST);
|
||||
asyncTest(() => analyze(uriList, WHITE_LIST));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ library analyze_api;
|
||||
import "package:expect/expect.dart";
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart';
|
||||
import 'analyze_helper.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
/**
|
||||
* Map of whitelisted warnings and errors.
|
||||
@@ -25,5 +26,5 @@ const Map<String,List<String>> WHITE_LIST = const {
|
||||
void main() {
|
||||
var uri = currentDirectory.resolve(
|
||||
'sdk/lib/_internal/compiler/implementation/dart2js.dart');
|
||||
analyze([uri], WHITE_LIST);
|
||||
asyncTest(() => analyze([uri], WHITE_LIST));
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
library analyze_helper;
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import '../../../sdk/lib/_internal/compiler/compiler.dart' as api;
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart';
|
||||
@@ -122,7 +123,7 @@ class CollectingDiagnosticHandler extends FormattingDiagnosticHandler {
|
||||
}
|
||||
}
|
||||
|
||||
void analyze(List<Uri> uriList, Map<String, List<String>> whiteList) {
|
||||
Future analyze(List<Uri> uriList, Map<String, List<String>> whiteList) {
|
||||
var libraryRoot = currentDirectory.resolve('sdk/');
|
||||
var provider = new SourceFileProvider();
|
||||
var handler = new CollectingDiagnosticHandler(whiteList, provider);
|
||||
@@ -134,6 +135,7 @@ void analyze(List<Uri> uriList, Map<String, List<String>> whiteList) {
|
||||
<String>['--analyze-only', '--analyze-all',
|
||||
'--categories=Client,Server']);
|
||||
compiler.librariesToAnalyzeWhenRun = uriList;
|
||||
compiler.run(null);
|
||||
handler.checkResults();
|
||||
return compiler.run(null).then((_) {
|
||||
handler.checkResults();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ library analyze_only;
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
import '../../utils/dummy_compiler_test.dart' as dummy;
|
||||
import '../../../sdk/lib/_internal/compiler/compiler.dart';
|
||||
@@ -34,6 +35,7 @@ runCompiler(String main, List<String> options,
|
||||
print('-----------------------------------------------');
|
||||
print('main source:\n$main');
|
||||
print('options: $options\n');
|
||||
asyncStart();
|
||||
Future<String> result =
|
||||
compile(new Uri(scheme: 'main'),
|
||||
new Uri(scheme: 'lib', path: '/'),
|
||||
@@ -43,7 +45,7 @@ runCompiler(String main, List<String> options,
|
||||
onValue(code, errors, warnings);
|
||||
}, onError: (e) {
|
||||
throw 'Compilation failed';
|
||||
});
|
||||
}).whenComplete(() => asyncEnd());
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// Copyright (c) 2012, 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.
|
||||
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/compiler.dart' as compiler;
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart';
|
||||
|
||||
const SOURCES = const {
|
||||
"/main.dart": """
|
||||
import "foo.dart";
|
||||
main() => foo();
|
||||
""",
|
||||
"/foo.dart": """
|
||||
library foo;
|
||||
import "bar.dart";
|
||||
foo() => bar();
|
||||
""",
|
||||
"/bar.dart": """
|
||||
library bar;
|
||||
bar() => print("bar");
|
||||
"""
|
||||
};
|
||||
|
||||
Future<String> provideInput(Uri uri) {
|
||||
var source = SOURCES[uri.path];
|
||||
if (source == null) {
|
||||
// Not one of our source files, so assume it's a built-in.
|
||||
source = new File(uriPathToNative(uri.path)).readAsStringSync();
|
||||
}
|
||||
|
||||
// Deliver the input asynchronously.
|
||||
return new Future(() => source);
|
||||
}
|
||||
|
||||
main() {
|
||||
var entrypoint = Uri.parse("file:///main.dart");
|
||||
|
||||
// Find the path to sdk/ in the repo relative to this script.
|
||||
Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script));
|
||||
Uri libraryRoot = script.resolve('../../../sdk/');
|
||||
Uri packageRoot = script.resolve('./packages/');
|
||||
|
||||
asyncStart();
|
||||
compiler.compile(entrypoint, libraryRoot, packageRoot,
|
||||
provideInput, handleDiagnostic, []).then((code) {
|
||||
Expect.isNotNull(code);
|
||||
}).whenComplete(() => asyncEnd());
|
||||
}
|
||||
|
||||
void handleDiagnostic(Uri uri, int begin, int end, String message,
|
||||
compiler.Diagnostic kind) {
|
||||
print(message);
|
||||
if (kind != compiler.Diagnostic.VERBOSE_INFO) {
|
||||
throw 'Unexpected diagnostic kind $kind';
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'memory_source_file_helper.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/compiler.dart'
|
||||
show Diagnostic;
|
||||
@@ -13,8 +14,7 @@ main() {
|
||||
Uri libraryRoot = script.resolve('../../../sdk/');
|
||||
Uri packageRoot = script.resolve('./packages/');
|
||||
|
||||
MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES;
|
||||
var provider = new MemorySourceFileProvider();
|
||||
var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
|
||||
int warningCount = 0;
|
||||
int errorCount = 0;
|
||||
void diagnosticHandler(Uri uri, int begin, int end,
|
||||
@@ -37,10 +37,12 @@ main() {
|
||||
libraryRoot,
|
||||
packageRoot,
|
||||
['--analyze-only']);
|
||||
compiler.run(Uri.parse('memory:main.dart'));
|
||||
Expect.isTrue(compiler.compilationFailed);
|
||||
Expect.equals(5, errorCount);
|
||||
Expect.equals(1, warningCount);
|
||||
asyncStart();
|
||||
compiler.run(Uri.parse('memory:main.dart')).then((_) {
|
||||
Expect.isTrue(compiler.compilationFailed);
|
||||
Expect.equals(5, errorCount);
|
||||
Expect.equals(1, warningCount);
|
||||
}).whenComplete(() => asyncEnd());
|
||||
}
|
||||
|
||||
const Map MEMORY_SOURCE_FILES = const {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'
|
||||
show TypeMask;
|
||||
|
||||
@@ -15,12 +16,14 @@ void compileAndFind(String code,
|
||||
bool disableInlining,
|
||||
check(compiler, element)) {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
asyncStart();
|
||||
var compiler = compilerFor(code, uri);
|
||||
compiler.disableInlining = disableInlining;
|
||||
compiler.runCompiler(uri);
|
||||
var cls = findElement(compiler, className);
|
||||
var member = cls.lookupLocalMember(buildSourceString(memberName));
|
||||
return check(compiler, member);
|
||||
compiler.runCompiler(uri).then((_) {
|
||||
var cls = findElement(compiler, className);
|
||||
var member = cls.lookupLocalMember(buildSourceString(memberName));
|
||||
return check(compiler, member);
|
||||
}).whenComplete(() => asyncEnd());
|
||||
}
|
||||
|
||||
const String TEST_1 = r"""
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
// Test that parameters keep their names in the output.
|
||||
|
||||
import 'dart:async';
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -87,15 +89,11 @@ main() {
|
||||
// At some point Dart2js generated bad object literals with dangling commas:
|
||||
// { a: true, }. Make sure this doesn't happen again.
|
||||
RegExp danglingComma = new RegExp(r',[ \n]*}');
|
||||
String generated = compileAll(TEST_ONE);
|
||||
Expect.isFalse(danglingComma.hasMatch(generated));
|
||||
|
||||
generated = compileAll(TEST_TWO);
|
||||
Expect.isFalse(danglingComma.hasMatch(generated));
|
||||
|
||||
generated = compileAll(TEST_THREE);
|
||||
Expect.isFalse(danglingComma.hasMatch(generated));
|
||||
|
||||
generated = compileAll(TEST_FOUR);
|
||||
Expect.isFalse(danglingComma.hasMatch(generated));
|
||||
asyncStart();
|
||||
Future.forEach([TEST_ONE, TEST_TWO, TEST_THREE, TEST_FOUR], (test) {
|
||||
return compileAll(test).then((generated) {
|
||||
Expect.isFalse(danglingComma.hasMatch(generated));
|
||||
});
|
||||
}).whenComplete(() => asyncEnd());
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
// Test that parameters keep their names in the output.
|
||||
|
||||
import 'dart:async';
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -64,9 +66,10 @@ main() {
|
||||
""";
|
||||
|
||||
twoClasses() {
|
||||
String generated = compileAll(TEST_ONE);
|
||||
Expect.isTrue(generated.contains('A: {"": "Object;"'));
|
||||
Expect.isTrue(generated.contains('B: {"": "Object;"'));
|
||||
asyncTest(() => compileAll(TEST_ONE).then((generated) {
|
||||
Expect.isTrue(generated.contains('A: {"": "Object;"'));
|
||||
Expect.isTrue(generated.contains('B: {"": "Object;"'));
|
||||
}));
|
||||
}
|
||||
|
||||
subClass() {
|
||||
@@ -75,18 +78,20 @@ subClass() {
|
||||
Expect.isTrue(generated.contains('B: {"": "A;"'));
|
||||
}
|
||||
|
||||
checkOutput(compileAll(TEST_TWO));
|
||||
checkOutput(compileAll(TEST_THREE));
|
||||
asyncTest(() => compileAll(TEST_TWO).then(checkOutput));
|
||||
asyncTest(() => compileAll(TEST_THREE).then(checkOutput));
|
||||
}
|
||||
|
||||
fieldTest() {
|
||||
String generated = compileAll(TEST_FOUR);
|
||||
Expect.isTrue(generated.contains(r"""B: {"": "A;y,z,x", static:"""));
|
||||
asyncTest(() => compileAll(TEST_FOUR).then((generated) {
|
||||
Expect.isTrue(generated.contains(r"""B: {"": "A;y,z,x", static:"""));
|
||||
}));
|
||||
}
|
||||
|
||||
constructor1() {
|
||||
String generated = compileAll(TEST_FIVE);
|
||||
Expect.isTrue(generated.contains(new RegExp(r"new [$a-z]+\.A\(a\);")));
|
||||
asyncTest(() => compileAll(TEST_FIVE).then((generated) {
|
||||
Expect.isTrue(generated.contains(new RegExp(r"new [$a-z]+\.A\(a\);")));
|
||||
}));
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// Test that parameters keep their names in the output.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST_ONE = r"""
|
||||
@@ -35,9 +36,11 @@ main() {
|
||||
// we just verify that their members are in the correct order.
|
||||
RegExp regexp = new RegExp(r"foo\$0?:(.|\n)*bar\$0:(.|\n)*gee\$0:");
|
||||
|
||||
String generated = compileAll(TEST_ONE);
|
||||
Expect.isTrue(regexp.hasMatch(generated));
|
||||
asyncTest(() => compileAll(TEST_ONE).then((generated) {
|
||||
Expect.isTrue(regexp.hasMatch(generated));
|
||||
}));
|
||||
|
||||
generated = compileAll(TEST_TWO);
|
||||
Expect.isTrue(regexp.hasMatch(generated));
|
||||
asyncTest(() => compileAll(TEST_TWO).then((generated) {
|
||||
Expect.isTrue(regexp.hasMatch(generated));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// Test that parameters keep their names in the output.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -52,10 +53,11 @@ closureInvocation() {
|
||||
// Make sure that the bailout version does not introduce a second version of
|
||||
// the closure.
|
||||
closureBailout() {
|
||||
String generated = compileAll(TEST_BAILOUT);
|
||||
RegExp regexp = new RegExp(r'call\$0: function');
|
||||
Iterator<Match> matches = regexp.allMatches(generated).iterator;
|
||||
checkNumberOfMatches(matches, 1);
|
||||
asyncTest(() => compileAll(TEST_BAILOUT).then((generated) {
|
||||
RegExp regexp = new RegExp(r'call\$0: function');
|
||||
Iterator<Match> matches = regexp.allMatches(generated).iterator;
|
||||
checkNumberOfMatches(matches, 1);
|
||||
}));
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
@@ -2,19 +2,20 @@
|
||||
// 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.
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
import 'memory_source_file_helper.dart';
|
||||
import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"
|
||||
show SourceString;
|
||||
|
||||
Map<String, String> generate(String code, [List<String> options = const []]) {
|
||||
Future<Map<String, String>> generate(String code,
|
||||
[List<String> options = const []]) {
|
||||
Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script));
|
||||
Uri libraryRoot = script.resolve('../../../sdk/');
|
||||
Uri packageRoot = script.resolve('./packages/');
|
||||
|
||||
MemorySourceFileProvider.MEMORY_SOURCE_FILES = { 'main.dart': code };
|
||||
var provider = new MemorySourceFileProvider();
|
||||
var provider = new MemorySourceFileProvider({ 'main.dart': code });
|
||||
var handler = new FormattingDiagnosticHandler(provider);
|
||||
|
||||
Compiler compiler = new Compiler(provider.readStringFromUri,
|
||||
@@ -24,13 +25,15 @@ Map<String, String> generate(String code, [List<String> options = const []]) {
|
||||
packageRoot,
|
||||
options);
|
||||
Uri uri = Uri.parse('memory:main.dart');
|
||||
Expect.isTrue(compiler.run(uri));
|
||||
Map<String, String> result = new Map<String, String>();
|
||||
for (var element in compiler.backend.generatedCode.keys) {
|
||||
if (element.getCompilationUnit().script.uri != uri) continue;
|
||||
var name = element.name.slowToString();
|
||||
var code = compiler.backend.assembleCode(element);
|
||||
result[name] = code;
|
||||
}
|
||||
return result;
|
||||
return compiler.run(uri).then((success) {
|
||||
Expect.isTrue(success);
|
||||
Map<String, String> result = new Map<String, String>();
|
||||
for (var element in compiler.backend.generatedCode.keys) {
|
||||
if (element.getCompilationUnit().script.uri != uri) continue;
|
||||
var name = element.name.slowToString();
|
||||
var code = compiler.backend.assembleCode(element);
|
||||
result[name] = code;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
library compiler_helper;
|
||||
|
||||
import 'dart:async';
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart'
|
||||
@@ -90,40 +91,42 @@ MockCompiler compilerFor(String code, Uri uri,
|
||||
return compiler;
|
||||
}
|
||||
|
||||
String compileAll(String code, {String coreSource: DEFAULT_CORELIB}) {
|
||||
Future<String> compileAll(String code, {String coreSource: DEFAULT_CORELIB}) {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
MockCompiler compiler = compilerFor(code, uri, coreSource: coreSource);
|
||||
compiler.runCompiler(uri);
|
||||
Expect.isFalse(compiler.compilationFailed,
|
||||
'Unexpected compilation error');
|
||||
return compiler.assembledCode;
|
||||
return compiler.runCompiler(uri).then((_) {
|
||||
Expect.isFalse(compiler.compilationFailed,
|
||||
'Unexpected compilation error');
|
||||
return compiler.assembledCode;
|
||||
});
|
||||
}
|
||||
|
||||
dynamic compileAndCheck(String code,
|
||||
String name,
|
||||
check(MockCompiler compiler, lego.Element element)) {
|
||||
Future compileAndCheck(String code,
|
||||
String name,
|
||||
check(MockCompiler compiler, lego.Element element)) {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
MockCompiler compiler = compilerFor(code, uri);
|
||||
compiler.runCompiler(uri);
|
||||
lego.Element element = findElement(compiler, name);
|
||||
return check(compiler, element);
|
||||
return compiler.runCompiler(uri).then((_) {
|
||||
lego.Element element = findElement(compiler, name);
|
||||
return check(compiler, element);
|
||||
});
|
||||
}
|
||||
|
||||
compileSources(Map<String, String> sources,
|
||||
Future compileSources(Map<String, String> sources,
|
||||
check(MockCompiler compiler)) {
|
||||
Uri base = new Uri(scheme: 'source');
|
||||
Uri mainUri = base.resolve('main.dart');
|
||||
String mainCode = sources['main.dart'];
|
||||
Expect.isNotNull(mainCode, 'No source code found for "main.dart"');
|
||||
MockCompiler compiler = compilerFor(mainCode, mainUri);
|
||||
|
||||
sources.forEach((String path, String code) {
|
||||
if (path == 'main.dart') return;
|
||||
compiler.registerSource(base.resolve(path), code);
|
||||
});
|
||||
|
||||
compiler.runCompiler(mainUri);
|
||||
return check(compiler);
|
||||
return compiler.runCompiler(mainUri).then((_) {
|
||||
return check(compiler);
|
||||
});
|
||||
}
|
||||
|
||||
lego.Element findElement(compiler, String name) {
|
||||
|
||||
@@ -2,21 +2,24 @@
|
||||
// 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.
|
||||
|
||||
import 'dart:async';
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
void compileAndFind(String code, String name,
|
||||
Future compileAndFind(String code, String name,
|
||||
check(compiler, element)) {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(code, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var element = findElement(compiler, name);
|
||||
return check(compiler, element);
|
||||
return compiler.runCompiler(uri).then((_) {
|
||||
var element = findElement(compiler, name);
|
||||
check(compiler, element);
|
||||
});
|
||||
}
|
||||
|
||||
void checkPrintType(String expression, checkType(compiler, type)) {
|
||||
compileAndFind(
|
||||
asyncTest(() => compileAndFind(
|
||||
'main() { print($expression); }',
|
||||
'print',
|
||||
(compiler, printElement) {
|
||||
@@ -24,9 +27,9 @@ void checkPrintType(String expression, checkType(compiler, type)) {
|
||||
printElement.computeSignature(compiler).requiredParameters.head;
|
||||
var type = compiler.typesTask.getGuaranteedTypeOfElement(parameter);
|
||||
checkType(compiler, type);
|
||||
});
|
||||
}));
|
||||
|
||||
compileAndFind(
|
||||
asyncTest(() => compileAndFind(
|
||||
'main() { var x = print; print($expression); }',
|
||||
'print',
|
||||
(compiler, printElement) {
|
||||
@@ -36,9 +39,9 @@ void checkPrintType(String expression, checkType(compiler, type)) {
|
||||
var inferrer = compiler.typesTask.typesInferrer;
|
||||
Expect.identical(compiler.typesTask.dynamicType,
|
||||
type.simplify(compiler));
|
||||
});
|
||||
}));
|
||||
|
||||
compileAndFind(
|
||||
asyncTest(() => compileAndFind(
|
||||
'main() { print($expression); print($expression); }',
|
||||
'print',
|
||||
(compiler, printElement) {
|
||||
@@ -46,7 +49,7 @@ void checkPrintType(String expression, checkType(compiler, type)) {
|
||||
printElement.computeSignature(compiler).requiredParameters.head;
|
||||
var type = compiler.typesTask.getGuaranteedTypeOfElement(parameter);
|
||||
checkType(compiler, type);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
void testBasicTypes() {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'parser_helper.dart';
|
||||
import 'mock_compiler.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/compiler.dart';
|
||||
@@ -129,13 +130,13 @@ testDart2DartWithLibrary(
|
||||
if (minify) options.add('--minify');
|
||||
if (stripTypes) options.add('--force-strip=types');
|
||||
|
||||
compile(
|
||||
asyncTest(() => compile(
|
||||
scriptUri,
|
||||
fileUri('libraryRoot/'),
|
||||
fileUri('packageRoot/'),
|
||||
provider,
|
||||
handler,
|
||||
options).then(continuation);
|
||||
options).then(continuation));
|
||||
}
|
||||
|
||||
testSimpleFileUnparse() {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// instruction gets removed from the graph when it's not used.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
String TEST = r'''
|
||||
@@ -32,7 +33,6 @@ foo(a) {
|
||||
|
||||
main() {
|
||||
String generated = compile(TEST, entry: 'foo');
|
||||
|
||||
// Check that we only have one bailout call. The second bailout call
|
||||
// is dead code because we know [:a.length:] is an int.
|
||||
checkNumberOfMatches(new RegExp('bailout').allMatches(generated).iterator, 1);
|
||||
@@ -49,20 +49,20 @@ main() {
|
||||
Expect.isTrue(!generated.contains('getInterceptor'));
|
||||
}
|
||||
|
||||
generated = compileAll(TEST);
|
||||
|
||||
// Check that the foo bailout method is generated.
|
||||
checkNumberOfMatches(
|
||||
new RegExp('foo\\\$bailout').allMatches(generated).iterator, 2);
|
||||
asyncTest(() => compileAll(TEST).then((generated) {
|
||||
// Check that the foo bailout method is generated.
|
||||
checkNumberOfMatches(
|
||||
new RegExp('foo\\\$bailout').allMatches(generated).iterator, 2);
|
||||
|
||||
// Check that it's the only bailout method.
|
||||
checkNumberOfMatches(new RegExp('bailout').allMatches(generated).iterator, 2);
|
||||
// Check that it's the only bailout method.
|
||||
checkNumberOfMatches(new RegExp('bailout').allMatches(generated).iterator, 2);
|
||||
|
||||
// Check that the bailout method has a case 2 for the state, which
|
||||
// is the second bailout in foo.
|
||||
Expect.isTrue(generated.contains('case 2:'));
|
||||
// Check that the bailout method has a case 2 for the state, which
|
||||
// is the second bailout in foo.
|
||||
Expect.isTrue(generated.contains('case 2:'));
|
||||
|
||||
// Finally, make sure that the reason foo does not contain
|
||||
// 'getInterceptor' is not because the compiler renamed it.
|
||||
Expect.isTrue(generated.contains('getInterceptor'));
|
||||
// Finally, make sure that the reason foo does not contain
|
||||
// 'getInterceptor' is not because the compiler renamed it.
|
||||
Expect.isTrue(generated.contains('getInterceptor'));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
String TEST = r'''
|
||||
@@ -16,6 +17,7 @@ foo(a) {
|
||||
''';
|
||||
|
||||
main() {
|
||||
String generated = compileAll(TEST);
|
||||
Expect.isFalse(generated.contains('return 42'), 'dead code not eliminated');
|
||||
asyncTest(() => compileAll(TEST).then((generated) {
|
||||
Expect.isFalse(generated.contains('return 42'), 'dead code not eliminated');
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// much be included in the initial download (loaded eagerly).
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'memory_source_file_helper.dart';
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart'
|
||||
@@ -17,8 +18,7 @@ void main() {
|
||||
Uri libraryRoot = script.resolve('../../../sdk/');
|
||||
Uri packageRoot = script.resolve('./packages/');
|
||||
|
||||
MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES;
|
||||
var provider = new MemorySourceFileProvider();
|
||||
var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
|
||||
var handler = new FormattingDiagnosticHandler(provider);
|
||||
|
||||
Compiler compiler = new Compiler(provider.readStringFromUri,
|
||||
@@ -27,26 +27,27 @@ void main() {
|
||||
libraryRoot,
|
||||
packageRoot,
|
||||
['--analyze-only']);
|
||||
compiler.run(Uri.parse('memory:main.dart'));
|
||||
var main = compiler.mainApp.find(dart2js.Compiler.MAIN);
|
||||
Expect.isNotNull(main, 'Could not find "main"');
|
||||
compiler.deferredLoadTask.onResolutionComplete(main);
|
||||
asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) {
|
||||
var main = compiler.mainApp.find(dart2js.Compiler.MAIN);
|
||||
Expect.isNotNull(main, 'Could not find "main"');
|
||||
compiler.deferredLoadTask.onResolutionComplete(main);
|
||||
|
||||
var deferredClasses =
|
||||
compiler.deferredLoadTask.allDeferredElements.where((e) => e.isClass())
|
||||
.toSet();
|
||||
var deferredClasses =
|
||||
compiler.deferredLoadTask.allDeferredElements.where((e) => e.isClass())
|
||||
.toSet();
|
||||
|
||||
var dateTime =
|
||||
deferredClasses
|
||||
.where((e) => e.name.slowToString() == 'DateTime').single;
|
||||
var dateTime =
|
||||
deferredClasses
|
||||
.where((e) => e.name.slowToString() == 'DateTime').single;
|
||||
|
||||
var myClass =
|
||||
deferredClasses.where((e) => e.name.slowToString() == 'MyClass').single;
|
||||
var myClass =
|
||||
deferredClasses.where((e) => e.name.slowToString() == 'MyClass').single;
|
||||
|
||||
var deferredLibrary = compiler.libraries['memory:deferred.dart'];
|
||||
var deferredLibrary = compiler.libraries['memory:deferred.dart'];
|
||||
|
||||
Expect.equals(deferredLibrary, myClass.getLibrary());
|
||||
Expect.equals(compiler.coreLibrary, dateTime.declaration.getLibrary());
|
||||
Expect.equals(deferredLibrary, myClass.getLibrary());
|
||||
Expect.equals(compiler.coreLibrary, dateTime.declaration.getLibrary());
|
||||
}));
|
||||
}
|
||||
|
||||
const Map MEMORY_SOURCE_FILES = const {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'memory_source_file_helper.dart';
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/compiler.dart'
|
||||
@@ -15,8 +16,7 @@ main() {
|
||||
Uri libraryRoot = script.resolve('../../../sdk/');
|
||||
Uri packageRoot = script.resolve('./packages/');
|
||||
|
||||
MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES;
|
||||
var provider = new MemorySourceFileProvider();
|
||||
var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
|
||||
var diagnostics = [];
|
||||
void diagnosticHandler(Uri uri, int begin, int end,
|
||||
String message, Diagnostic kind) {
|
||||
@@ -32,28 +32,30 @@ main() {
|
||||
libraryRoot,
|
||||
packageRoot,
|
||||
['--analyze-only']);
|
||||
compiler.run(Uri.parse('memory:main.dart'));
|
||||
diagnostics.sort();
|
||||
var expected = [
|
||||
'memory:exporter.dart:43:47:Info: "function(hest)" is defined here.:info',
|
||||
'memory:library.dart:14:19:Info: "class(Fisk)" is (re)exported by '
|
||||
'multiple libraries.:info',
|
||||
'memory:library.dart:30:34:Info: "function(fisk)" is (re)exported by '
|
||||
'multiple libraries.:info',
|
||||
'memory:library.dart:41:45:Info: "function(hest)" is defined here.'
|
||||
':info',
|
||||
'memory:main.dart:0:22:Info: "class(Fisk)" is imported here.:info',
|
||||
'memory:main.dart:0:22:Info: "function(fisk)" is imported here.:info',
|
||||
'memory:main.dart:0:22:Info: "function(hest)" is imported here.:info',
|
||||
'memory:main.dart:23:46:Info: "class(Fisk)" is imported here.:info',
|
||||
'memory:main.dart:23:46:Info: "function(fisk)" is imported here.:info',
|
||||
'memory:main.dart:23:46:Info: "function(hest)" is imported here.:info',
|
||||
'memory:main.dart:59:63:Warning: Duplicate import of "Fisk".:warning',
|
||||
'memory:main.dart:76:80:Error: Duplicate import of "fisk".:error',
|
||||
'memory:main.dart:86:90:Error: Duplicate import of "hest".:error'
|
||||
];
|
||||
Expect.listEquals(expected, diagnostics);
|
||||
Expect.isTrue(compiler.compilationFailed);
|
||||
asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) {
|
||||
diagnostics.sort();
|
||||
var expected = [
|
||||
'memory:exporter.dart:43:47:Info: "function(hest)" is defined here.'
|
||||
':info',
|
||||
'memory:library.dart:14:19:Info: "class(Fisk)" is (re)exported by '
|
||||
'multiple libraries.:info',
|
||||
'memory:library.dart:30:34:Info: "function(fisk)" is (re)exported by '
|
||||
'multiple libraries.:info',
|
||||
'memory:library.dart:41:45:Info: "function(hest)" is defined here.'
|
||||
':info',
|
||||
'memory:main.dart:0:22:Info: "class(Fisk)" is imported here.:info',
|
||||
'memory:main.dart:0:22:Info: "function(fisk)" is imported here.:info',
|
||||
'memory:main.dart:0:22:Info: "function(hest)" is imported here.:info',
|
||||
'memory:main.dart:23:46:Info: "class(Fisk)" is imported here.:info',
|
||||
'memory:main.dart:23:46:Info: "function(fisk)" is imported here.:info',
|
||||
'memory:main.dart:23:46:Info: "function(hest)" is imported here.:info',
|
||||
'memory:main.dart:59:63:Warning: Duplicate import of "Fisk".:warning',
|
||||
'memory:main.dart:76:80:Error: Duplicate import of "fisk".:error',
|
||||
'memory:main.dart:86:90:Error: Duplicate import of "hest".:error'
|
||||
];
|
||||
Expect.listEquals(expected, diagnostics);
|
||||
Expect.isTrue(compiler.compilationFailed);
|
||||
}));
|
||||
}
|
||||
|
||||
const Map MEMORY_SOURCE_FILES = const {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// Test that unused static consts are not emitted.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST_GUIDE = r"""
|
||||
@@ -18,8 +19,9 @@ main() {
|
||||
""";
|
||||
|
||||
main() {
|
||||
String generated = compileAll(TEST_GUIDE);
|
||||
Expect.isTrue(generated.contains("42"));
|
||||
Expect.isFalse(generated.contains("TITLE"));
|
||||
asyncTest(() => compileAll(TEST_GUIDE).then((generated) {
|
||||
Expect.isTrue(generated.contains("42"));
|
||||
Expect.isFalse(generated.contains("TITLE"));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// Test that parameters keep their names in the output.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -20,8 +21,11 @@ main() { return x; }
|
||||
""";
|
||||
|
||||
main() {
|
||||
String generated = compileAll(TEST_NULL0);
|
||||
Expect.isTrue(generated.contains("null"));
|
||||
generated = compileAll(TEST_NULL1);
|
||||
Expect.isTrue(generated.contains("null"));
|
||||
asyncTest(() => compileAll(TEST_NULL0).then((generated) {
|
||||
Expect.isTrue(generated.contains("null"));
|
||||
}));
|
||||
|
||||
asyncTest(() => compileAll(TEST_NULL1).then((generated) {
|
||||
Expect.isTrue(generated.contains("null"));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// 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.
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'
|
||||
show TypeMask;
|
||||
|
||||
@@ -16,11 +18,12 @@ void compileAndFind(String code,
|
||||
check(compiler, element)) {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(code, uri);
|
||||
compiler.runCompiler(uri);
|
||||
compiler.disableInlining = disableInlining;
|
||||
var cls = findElement(compiler, className);
|
||||
var member = cls.lookupMember(buildSourceString(memberName));
|
||||
return check(compiler, member);
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
compiler.disableInlining = disableInlining;
|
||||
var cls = findElement(compiler, className);
|
||||
var member = cls.lookupMember(buildSourceString(memberName));
|
||||
check(compiler, member);
|
||||
}));
|
||||
}
|
||||
|
||||
const String TEST_1 = r"""
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// effects.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -24,16 +25,17 @@ main() {
|
||||
main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
String generated = compiler.assembledCode;
|
||||
RegExp regexp = new RegExp(r"get\$foo");
|
||||
Iterator matches = regexp.allMatches(generated).iterator;
|
||||
checkNumberOfMatches(matches, 1);
|
||||
var cls = findElement(compiler, 'A');
|
||||
Expect.isNotNull(cls);
|
||||
SourceString name = buildSourceString('foo');
|
||||
var element = cls.lookupLocalMember(name);
|
||||
Expect.isNotNull(element);
|
||||
Selector selector = new Selector.getter(name, null);
|
||||
Expect.isFalse(compiler.world.hasAnyUserDefinedGetter(selector));
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
String generated = compiler.assembledCode;
|
||||
RegExp regexp = new RegExp(r"get\$foo");
|
||||
Iterator matches = regexp.allMatches(generated).iterator;
|
||||
checkNumberOfMatches(matches, 1);
|
||||
var cls = findElement(compiler, 'A');
|
||||
Expect.isNotNull(cls);
|
||||
SourceString name = buildSourceString('foo');
|
||||
var element = cls.lookupLocalMember(name);
|
||||
Expect.isNotNull(element);
|
||||
Selector selector = new Selector.getter(name, null);
|
||||
Expect.isFalse(compiler.world.hasAnyUserDefinedGetter(selector));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST_ONE = r"""
|
||||
@@ -118,16 +119,20 @@ main() {
|
||||
generated = compile(TEST_FOUR, entry: 'foo');
|
||||
checkNumberOfMatches(new RegExp("shr").allMatches(generated).iterator, 1);
|
||||
|
||||
generated = compileAll(TEST_FIVE);
|
||||
checkNumberOfMatches(
|
||||
new RegExp("get\\\$foo").allMatches(generated).iterator, 1);
|
||||
asyncTest(() => compileAll(TEST_FIVE).then((generated) {
|
||||
checkNumberOfMatches(
|
||||
new RegExp("get\\\$foo").allMatches(generated).iterator, 1);
|
||||
}));
|
||||
|
||||
generated = compileAll(TEST_SIX);
|
||||
Expect.isTrue(generated.contains('for (t1 = a.field === 54; t1;)'));
|
||||
asyncTest(() => compileAll(TEST_SIX).then((generated) {
|
||||
Expect.isTrue(generated.contains('for (t1 = a.field === 54; t1;)'));
|
||||
}));
|
||||
|
||||
generated = compileAll(TEST_SEVEN);
|
||||
Expect.isTrue(generated.contains('for (t1 = a.field === 54; t1;)'));
|
||||
asyncTest(() => compileAll(TEST_SEVEN).then((generated) {
|
||||
Expect.isTrue(generated.contains('for (t1 = a.field === 54; t1;)'));
|
||||
}));
|
||||
|
||||
generated = compileAll(TEST_EIGHT);
|
||||
Expect.isTrue(generated.contains('for (; i < t1; ++i)'));
|
||||
asyncTest(() => compileAll(TEST_EIGHT).then((generated) {
|
||||
Expect.isTrue(generated.contains('for (; i < t1; ++i)'));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
library dart2js.test.import;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'memory_compiler.dart';
|
||||
|
||||
const MEMORY_SOURCE_FILES = const {
|
||||
@@ -30,17 +31,19 @@ main() {
|
||||
testMissingImports() {
|
||||
var collector = new DiagnosticCollector();
|
||||
var compiler = compilerFor(MEMORY_SOURCE_FILES, diagnosticHandler: collector);
|
||||
compiler.run(Uri.parse('memory:main.dart'));
|
||||
Expect.equals(4, collector.errors.length);
|
||||
Expect.equals(1, collector.warnings.length);
|
||||
asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) {
|
||||
Expect.equals(4, collector.errors.length);
|
||||
Expect.equals(1, collector.warnings.length);
|
||||
}));
|
||||
}
|
||||
|
||||
testMissingMain() {
|
||||
var collector = new DiagnosticCollector();
|
||||
var compiler = compilerFor({}, diagnosticHandler: collector);
|
||||
compiler.run(Uri.parse('memory:missing.dart'));
|
||||
Expect.equals(1, collector.errors.length);
|
||||
Expect.equals(0, collector.warnings.length);
|
||||
asyncTest(() => compiler.run(Uri.parse('memory:missing.dart')).then((_) {
|
||||
Expect.equals(1, collector.errors.length);
|
||||
Expect.equals(0, collector.warnings.length);
|
||||
}));
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST1 = r"""
|
||||
@@ -22,9 +23,10 @@ main() {
|
||||
""";
|
||||
|
||||
main() {
|
||||
String generated = compileAll(TEST1);
|
||||
// Check that we're using the index operator on the object returned
|
||||
// by the A factory.
|
||||
Expect.isTrue(generated.contains('[0] = 42'));
|
||||
asyncTest(() => compileAll(TEST1).then((generated) {
|
||||
// Check that we're using the index operator on the object returned
|
||||
// by the A factory.
|
||||
Expect.isTrue(generated.contains('[0] = 42'));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright (c) 2013, 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'mock_compiler.dart';
|
||||
|
||||
class ScanMockCompiler extends MockCompiler {
|
||||
ScanMockCompiler() {
|
||||
isolateHelperLibrary = null;
|
||||
foreignLibrary = null;
|
||||
}
|
||||
|
||||
LibraryElement scanBuiltinLibrary(String filename) {
|
||||
return createLibrary(filename, "main(){}");
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
Compiler compiler = new ScanMockCompiler();
|
||||
Expect.equals(null, compiler.isolateHelperLibrary);
|
||||
Expect.equals(null, compiler.foreignLibrary);
|
||||
compiler.onLibraryLoaded(mockLibrary(compiler, "mock"),
|
||||
new Uri(scheme: 'dart', path: '_isolate_helper'));
|
||||
Expect.isTrue(compiler.isolateHelperLibrary != null);
|
||||
compiler.onLibraryLoaded(mockLibrary(compiler, "mock"),
|
||||
new Uri(scheme: 'dart', path: '_foreign_helper'));
|
||||
Expect.isTrue(compiler.isolateHelperLibrary != null);
|
||||
Expect.equals(new Uri(scheme: 'dart', path: '_isolate_helper'),
|
||||
compiler.isolateHelperLibrary.canonicalUri);
|
||||
Expect.isTrue(compiler.foreignLibrary != null);
|
||||
Expect.equals(new Uri(scheme: 'dart', path: '_foreign_helper'),
|
||||
compiler.foreignLibrary.canonicalUri);
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
// the presence of a fixed length list constructor call.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import
|
||||
'../../../sdk/lib/_internal/compiler/implementation/types/types.dart'
|
||||
show ContainerTypeMask, TypeMask;
|
||||
@@ -25,14 +26,15 @@ main() {
|
||||
void main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
|
||||
checkType(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
ContainerTypeMask mask = typesInferrer.getTypeOfElement(element);
|
||||
Expect.equals(type, mask.elementType.simplify(compiler), name);
|
||||
}
|
||||
checkType(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
ContainerTypeMask mask = typesInferrer.getTypeOfElement(element);
|
||||
Expect.equals(type, mask.elementType.simplify(compiler), name);
|
||||
}
|
||||
|
||||
checkType('myList', compiler.typesTask.intType);
|
||||
checkType('myList', compiler.typesTask.intType);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST1 = r"""
|
||||
@@ -63,8 +64,9 @@ main() {
|
||||
""";
|
||||
|
||||
void checkRangeError(String test, {bool hasRangeError}) {
|
||||
String generated = compileAll(test);
|
||||
Expect.equals(hasRangeError, generated.contains('ioore'));
|
||||
asyncTest(() => compileAll(test).then((generated) {
|
||||
Expect.equals(hasRangeError, generated.contains('ioore'));
|
||||
}));
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST1 = r"""
|
||||
@@ -57,28 +58,34 @@ main() {
|
||||
|
||||
|
||||
main() {
|
||||
String generated = compileAll(TEST1);
|
||||
// Check that we only do a null check on the receiver for
|
||||
// [: a[0] + 42 :]. We can do a null check because we inferred that
|
||||
// the list is of type int or null.
|
||||
Expect.isFalse(generated.contains('if (typeof t1'));
|
||||
Expect.isTrue(generated.contains('if (t1 == null)'));
|
||||
asyncTest(() => compileAll(TEST1).then((generated) {
|
||||
// Check that we only do a null check on the receiver for
|
||||
// [: a[0] + 42 :]. We can do a null check because we inferred that
|
||||
// the list is of type int or null.
|
||||
Expect.isFalse(generated.contains('if (typeof t1'));
|
||||
Expect.isTrue(generated.contains('if (t1 == null)'));
|
||||
}));
|
||||
|
||||
generated = compileAll(TEST2);
|
||||
Expect.isFalse(generated.contains('if (typeof t1'));
|
||||
Expect.isTrue(generated.contains('if (t1 == null)'));
|
||||
asyncTest(() => compileAll(TEST2).then((generated) {
|
||||
Expect.isFalse(generated.contains('if (typeof t1'));
|
||||
Expect.isTrue(generated.contains('if (t1 == null)'));
|
||||
}));
|
||||
|
||||
generated = compileAll(TEST3);
|
||||
Expect.isFalse(generated.contains('if (typeof t1'));
|
||||
Expect.isTrue(generated.contains('if (t1 == null)'));
|
||||
asyncTest(() => compileAll(TEST3).then((generated) {
|
||||
Expect.isFalse(generated.contains('if (typeof t1'));
|
||||
Expect.isTrue(generated.contains('if (t1 == null)'));
|
||||
}));
|
||||
|
||||
generated = compileAll(TEST4);
|
||||
Expect.isFalse(generated.contains('if (typeof t1'));
|
||||
Expect.isTrue(generated.contains('if (t1 == null)'));
|
||||
asyncTest(() => compileAll(TEST4).then((generated) {
|
||||
Expect.isFalse(generated.contains('if (typeof t1'));
|
||||
Expect.isTrue(generated.contains('if (t1 == null)'));
|
||||
}));
|
||||
|
||||
generated = compileAll(TEST5);
|
||||
Expect.isFalse(generated.contains('iae'));
|
||||
asyncTest(() => compileAll(TEST5).then((generated) {
|
||||
Expect.isFalse(generated.contains('iae'));
|
||||
}));
|
||||
|
||||
generated = compileAll(TEST6);
|
||||
Expect.isFalse(generated.contains('iae'));
|
||||
asyncTest(() => compileAll(TEST6).then((generated) {
|
||||
Expect.isFalse(generated.contains('iae'));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import
|
||||
'../../../sdk/lib/_internal/compiler/implementation/types/types.dart'
|
||||
show ContainerTypeMask, TypeMask;
|
||||
@@ -189,43 +190,44 @@ void main() {
|
||||
void doTest(String allocation, {bool nullify}) {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(generateTest(allocation), uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesTask = compiler.typesTask;
|
||||
var typesInferrer = typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesTask = compiler.typesTask;
|
||||
var typesInferrer = typesTask.typesInferrer;
|
||||
|
||||
checkType(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
ContainerTypeMask mask = typesInferrer.getTypeOfElement(element);
|
||||
if (nullify) type = type.nullable();
|
||||
Expect.equals(type, mask.elementType.simplify(compiler), name);
|
||||
}
|
||||
checkType(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
ContainerTypeMask mask = typesInferrer.getTypeOfElement(element);
|
||||
if (nullify) type = type.nullable();
|
||||
Expect.equals(type, mask.elementType.simplify(compiler), name);
|
||||
}
|
||||
|
||||
checkType('listInField', typesTask.numType);
|
||||
checkType('listPassedToMethod', typesTask.numType);
|
||||
checkType('listReturnedFromMethod', typesTask.numType);
|
||||
checkType('listUsedWithCascade', typesTask.numType);
|
||||
checkType('listUsedInClosure', typesTask.numType);
|
||||
checkType('listPassedToSelector', typesTask.numType);
|
||||
checkType('listReturnedFromSelector', typesTask.numType);
|
||||
checkType('listUsedWithAddAndInsert', typesTask.numType);
|
||||
checkType('listUsedWithConstraint', typesTask.numType);
|
||||
checkType('listEscapingFromSetter', typesTask.numType);
|
||||
checkType('listUsedInLocal', typesTask.numType);
|
||||
checkType('listEscapingInSetterValue', typesTask.numType);
|
||||
checkType('listEscapingInIndex', typesTask.numType);
|
||||
checkType('listEscapingInIndexSet', typesTask.intType);
|
||||
checkType('listEscapingTwiceInIndexSet', typesTask.numType);
|
||||
checkType('listSetInNonFinalField', typesTask.numType);
|
||||
checkType('listWithChangedLength', typesTask.intType.nullable());
|
||||
checkType('listInField', typesTask.numType);
|
||||
checkType('listPassedToMethod', typesTask.numType);
|
||||
checkType('listReturnedFromMethod', typesTask.numType);
|
||||
checkType('listUsedWithCascade', typesTask.numType);
|
||||
checkType('listUsedInClosure', typesTask.numType);
|
||||
checkType('listPassedToSelector', typesTask.numType);
|
||||
checkType('listReturnedFromSelector', typesTask.numType);
|
||||
checkType('listUsedWithAddAndInsert', typesTask.numType);
|
||||
checkType('listUsedWithConstraint', typesTask.numType);
|
||||
checkType('listEscapingFromSetter', typesTask.numType);
|
||||
checkType('listUsedInLocal', typesTask.numType);
|
||||
checkType('listEscapingInSetterValue', typesTask.numType);
|
||||
checkType('listEscapingInIndex', typesTask.numType);
|
||||
checkType('listEscapingInIndexSet', typesTask.intType);
|
||||
checkType('listEscapingTwiceInIndexSet', typesTask.numType);
|
||||
checkType('listSetInNonFinalField', typesTask.numType);
|
||||
checkType('listWithChangedLength', typesTask.intType.nullable());
|
||||
|
||||
checkType('listPassedToClosure', typesTask.dynamicType);
|
||||
checkType('listReturnedFromClosure', typesTask.dynamicType);
|
||||
checkType('listUsedWithNonOkSelector', typesTask.dynamicType);
|
||||
checkType('listPassedAsOptionalParameter', typesTask.dynamicType);
|
||||
checkType('listPassedAsNamedParameter', typesTask.dynamicType);
|
||||
checkType('listPassedToClosure', typesTask.dynamicType);
|
||||
checkType('listReturnedFromClosure', typesTask.dynamicType);
|
||||
checkType('listUsedWithNonOkSelector', typesTask.dynamicType);
|
||||
checkType('listPassedAsOptionalParameter', typesTask.dynamicType);
|
||||
checkType('listPassedAsNamedParameter', typesTask.dynamicType);
|
||||
|
||||
if (!allocation.contains('filled')) {
|
||||
checkType('listUnset', new TypeMask.nonNullEmpty());
|
||||
checkType('listOnlySetWithConstraint', new TypeMask.nonNullEmpty());
|
||||
}
|
||||
if (!allocation.contains('filled')) {
|
||||
checkType('listUnset', new TypeMask.nonNullEmpty());
|
||||
checkType('listOnlySetWithConstraint', new TypeMask.nonNullEmpty());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,76 +1,78 @@
|
||||
// Copyright (c) 2013, 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.
|
||||
|
||||
library subtype_test;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'type_test_helper.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart';
|
||||
import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart"
|
||||
show Element, ClassElement;
|
||||
|
||||
void main() {
|
||||
test();
|
||||
}
|
||||
|
||||
void test() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
class A<T> {
|
||||
T foo;
|
||||
}
|
||||
class B<S> extends A<A<S>> {
|
||||
S bar;
|
||||
}
|
||||
class C<U> extends B<String> with D<B<U>> {
|
||||
U baz;
|
||||
}
|
||||
class D<V> {
|
||||
V boz;
|
||||
}
|
||||
""");
|
||||
|
||||
void expect(DartType receiverType, String memberName, DartType expectedType) {
|
||||
Member member = receiverType.lookupMember(env.sourceString(memberName));
|
||||
Expect.isNotNull(member);
|
||||
DartType memberType = member.computeType(env.compiler);
|
||||
Expect.equals(expectedType, memberType,
|
||||
'Wrong member type for $receiverType.$memberName.');
|
||||
}
|
||||
|
||||
DartType int_ = env['int'];
|
||||
DartType String_ = env['String'];
|
||||
|
||||
ClassElement A = env.getElement('A');
|
||||
DartType T = A.typeVariables.head;
|
||||
DartType A_T = A.thisType;
|
||||
expect(A_T, 'foo', T);
|
||||
|
||||
DartType A_int = instantiate(A, [int_]);
|
||||
expect(A_int, 'foo', int_);
|
||||
|
||||
ClassElement B = env.getElement('B');
|
||||
DartType S = B.typeVariables.head;
|
||||
DartType B_S = B.thisType;
|
||||
expect(B_S, 'foo', instantiate(A, [S]));
|
||||
expect(B_S, 'bar', S);
|
||||
|
||||
DartType B_int = instantiate(B, [int_]);
|
||||
expect(B_int, 'foo', A_int);
|
||||
expect(B_int, 'bar', int_);
|
||||
|
||||
ClassElement C = env.getElement('C');
|
||||
DartType U = C.typeVariables.head;
|
||||
DartType C_U = C.thisType;
|
||||
expect(C_U, 'foo', instantiate(A, [String_]));
|
||||
expect(C_U, 'bar', String_);
|
||||
expect(C_U, 'baz', U);
|
||||
expect(C_U, 'boz', instantiate(B, [U]));
|
||||
|
||||
DartType C_int = instantiate(C, [int_]);
|
||||
expect(C_int, 'foo', instantiate(A, [String_]));
|
||||
expect(C_int, 'bar', String_);
|
||||
expect(C_int, 'baz', int_);
|
||||
expect(C_int, 'boz', instantiate(B, [int_]));
|
||||
}
|
||||
|
||||
// Copyright (c) 2013, 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.
|
||||
|
||||
library subtype_test;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'type_test_helper.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart';
|
||||
import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart"
|
||||
show Element, ClassElement;
|
||||
|
||||
void main() {
|
||||
test();
|
||||
}
|
||||
|
||||
void test() {
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
class A<T> {
|
||||
T foo;
|
||||
}
|
||||
class B<S> extends A<A<S>> {
|
||||
S bar;
|
||||
}
|
||||
class C<U> extends B<String> with D<B<U>> {
|
||||
U baz;
|
||||
}
|
||||
class D<V> {
|
||||
V boz;
|
||||
}
|
||||
""").then((env) {
|
||||
void expect(DartType receiverType, String memberName,
|
||||
DartType expectedType) {
|
||||
Member member = receiverType.lookupMember(env.sourceString(memberName));
|
||||
Expect.isNotNull(member);
|
||||
DartType memberType = member.computeType(env.compiler);
|
||||
Expect.equals(expectedType, memberType,
|
||||
'Wrong member type for $receiverType.$memberName.');
|
||||
}
|
||||
|
||||
DartType int_ = env['int'];
|
||||
DartType String_ = env['String'];
|
||||
|
||||
ClassElement A = env.getElement('A');
|
||||
DartType T = A.typeVariables.head;
|
||||
DartType A_T = A.thisType;
|
||||
expect(A_T, 'foo', T);
|
||||
|
||||
DartType A_int = instantiate(A, [int_]);
|
||||
expect(A_int, 'foo', int_);
|
||||
|
||||
ClassElement B = env.getElement('B');
|
||||
DartType S = B.typeVariables.head;
|
||||
DartType B_S = B.thisType;
|
||||
expect(B_S, 'foo', instantiate(A, [S]));
|
||||
expect(B_S, 'bar', S);
|
||||
|
||||
DartType B_int = instantiate(B, [int_]);
|
||||
expect(B_int, 'foo', A_int);
|
||||
expect(B_int, 'bar', int_);
|
||||
|
||||
ClassElement C = env.getElement('C');
|
||||
DartType U = C.typeVariables.head;
|
||||
DartType C_U = C.thisType;
|
||||
expect(C_U, 'foo', instantiate(A, [String_]));
|
||||
expect(C_U, 'bar', String_);
|
||||
expect(C_U, 'baz', U);
|
||||
expect(C_U, 'boz', instantiate(B, [U]));
|
||||
|
||||
DartType C_int = instantiate(C, [int_]);
|
||||
expect(C_int, 'foo', instantiate(A, [String_]));
|
||||
expect(C_int, 'bar', String_);
|
||||
expect(C_int, 'baz', int_);
|
||||
expect(C_int, 'boz', instantiate(B, [int_]));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -83,8 +83,7 @@ Compiler compilerFor(Map<String,String> memorySourceFiles,
|
||||
Uri libraryRoot = script.resolve('../../../sdk/');
|
||||
Uri packageRoot = script.resolve('./packages/');
|
||||
|
||||
MemorySourceFileProvider.MEMORY_SOURCE_FILES = memorySourceFiles;
|
||||
var provider = new MemorySourceFileProvider();
|
||||
var provider = new MemorySourceFileProvider(memorySourceFiles);
|
||||
var handler =
|
||||
createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics);
|
||||
|
||||
@@ -93,7 +92,7 @@ Compiler compilerFor(Map<String,String> memorySourceFiles,
|
||||
return new NullSink('$name.$extension');
|
||||
}
|
||||
|
||||
Compiler compiler = new Compiler(provider,
|
||||
Compiler compiler = new Compiler(provider.readStringFromUri,
|
||||
outputProvider,
|
||||
handler,
|
||||
libraryRoot,
|
||||
@@ -141,8 +140,7 @@ Future<MirrorSystem> mirrorSystemFor(Map<String,String> memorySourceFiles,
|
||||
Uri libraryRoot = script.resolve('../../../sdk/');
|
||||
Uri packageRoot = script.resolve('./packages/');
|
||||
|
||||
MemorySourceFileProvider.MEMORY_SOURCE_FILES = memorySourceFiles;
|
||||
var provider = new MemorySourceFileProvider();
|
||||
var provider = new MemorySourceFileProvider(memorySourceFiles);
|
||||
var handler =
|
||||
createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics);
|
||||
|
||||
|
||||
@@ -24,14 +24,17 @@ export '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
|
||||
show SourceFileProvider, FormattingDiagnosticHandler;
|
||||
|
||||
class MemorySourceFileProvider extends SourceFileProvider {
|
||||
static Map MEMORY_SOURCE_FILES;
|
||||
final Map<String, String> memorySourceFiles;
|
||||
|
||||
MemorySourceFileProvider(Map<String, String> this.memorySourceFiles);
|
||||
|
||||
Future<String> readStringFromUri(Uri resourceUri) {
|
||||
if (resourceUri.scheme != 'memory') {
|
||||
return super.readStringFromUri(resourceUri);
|
||||
}
|
||||
String source = MEMORY_SOURCE_FILES[resourceUri.path];
|
||||
String source = memorySourceFiles[resourceUri.path];
|
||||
// TODO(ahe): Return new Future.error(...) ?
|
||||
if (source == null) throw 'No such file $resourceUri';
|
||||
if (source == null) return new Future.error('No such file $resourceUri');
|
||||
String resourceName = '$resourceUri';
|
||||
this.sourceFiles[resourceName] = new SourceFile(resourceName, source);
|
||||
return new Future.value(source);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
library dart2js.test.message_kind_helper;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show
|
||||
Compiler,
|
||||
@@ -14,7 +15,7 @@ import 'memory_compiler.dart';
|
||||
|
||||
const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]';
|
||||
|
||||
Compiler check(MessageKind kind, Compiler cachedCompiler) {
|
||||
Future<Compiler> check(MessageKind kind, Compiler cachedCompiler) {
|
||||
Expect.isNotNull(kind.howToFix);
|
||||
Expect.isFalse(kind.examples.isEmpty);
|
||||
|
||||
@@ -33,21 +34,22 @@ Compiler check(MessageKind kind, Compiler cachedCompiler) {
|
||||
options: ['--analyze-only'],
|
||||
cachedCompiler: cachedCompiler);
|
||||
|
||||
compiler.run(Uri.parse('memory:main.dart'));
|
||||
return compiler.run(Uri.parse('memory:main.dart')).then((_) {
|
||||
|
||||
Expect.isFalse(messages.isEmpty, 'No messages in """$example"""');
|
||||
Expect.isFalse(messages.isEmpty, 'No messages in """$example"""');
|
||||
|
||||
String expectedText = !kind.hasHowToFix
|
||||
? kind.template : '${kind.template}\n${kind.howToFix}';
|
||||
String pattern = expectedText.replaceAllMapped(
|
||||
new RegExp(ESCAPE_REGEXP), (m) => '\\${m[0]}');
|
||||
pattern = pattern.replaceAll(new RegExp(r'#\\\{[^}]*\\\}'), '.*');
|
||||
String expectedText = !kind.hasHowToFix
|
||||
? kind.template : '${kind.template}\n${kind.howToFix}';
|
||||
String pattern = expectedText.replaceAllMapped(
|
||||
new RegExp(ESCAPE_REGEXP), (m) => '\\${m[0]}');
|
||||
pattern = pattern.replaceAll(new RegExp(r'#\\\{[^}]*\\\}'), '.*');
|
||||
|
||||
for (String message in messages) {
|
||||
Expect.isTrue(new RegExp('^$pattern\$').hasMatch(message),
|
||||
'"$pattern" does not match "$message"');
|
||||
}
|
||||
cachedCompiler = compiler;
|
||||
for (String message in messages) {
|
||||
Expect.isTrue(new RegExp('^$pattern\$').hasMatch(message),
|
||||
'"$pattern" does not match "$message"');
|
||||
}
|
||||
return compiler;
|
||||
});
|
||||
}
|
||||
|
||||
return cachedCompiler;
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
// 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.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'dart:async';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show
|
||||
DualKind,
|
||||
MessageKind;
|
||||
@@ -43,10 +46,14 @@ main() {
|
||||
}
|
||||
};
|
||||
var cachedCompiler;
|
||||
for (String name in examples) {
|
||||
asyncTest(() => Future.forEach(examples, (String name) {
|
||||
Stopwatch sw = new Stopwatch()..start();
|
||||
cachedCompiler = check(kinds[name], cachedCompiler);
|
||||
sw.stop();
|
||||
print("Checked '$name' in ${sw.elapsedMilliseconds}ms.");
|
||||
}
|
||||
return check(kinds[name], cachedCompiler).
|
||||
then((var compiler) {
|
||||
cachedCompiler = compiler;
|
||||
sw.stop();
|
||||
print("Checked '$name' in ${sw.elapsedMilliseconds}ms.");
|
||||
});
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -20,16 +21,14 @@ void checkPosition(Spannable spannable, Node node, String source, compiler) {
|
||||
|
||||
void checkAnnotation(String name, String declaration,
|
||||
{bool isTopLevelOnly: false}) {
|
||||
var source;
|
||||
|
||||
// Ensure that a compile-time constant can be resolved from an
|
||||
// annotation.
|
||||
source = """const native = 'xyz';
|
||||
@native
|
||||
$declaration
|
||||
main() {}""";
|
||||
var source1 = """const native = 'xyz';
|
||||
@native
|
||||
$declaration
|
||||
main() {}""";
|
||||
|
||||
compileAndCheck(source, name, (compiler, element) {
|
||||
compileAndCheck(source1, name, (compiler, element) {
|
||||
compiler.enqueuer.resolution.queueIsClosed = false;
|
||||
Expect.equals(1, length(element.metadata));
|
||||
PartialMetadataAnnotation annotation = element.metadata.head;
|
||||
@@ -37,17 +36,17 @@ void checkAnnotation(String name, String declaration,
|
||||
Constant value = annotation.value;
|
||||
Expect.stringEquals('xyz', value.value.slowToString());
|
||||
|
||||
checkPosition(annotation, annotation.cachedNode, source, compiler);
|
||||
checkPosition(annotation, annotation.cachedNode, source1, compiler);
|
||||
});
|
||||
|
||||
// Ensure that each repeated annotation has a unique instance of
|
||||
// [MetadataAnnotation].
|
||||
source = """const native = 'xyz';
|
||||
@native @native
|
||||
$declaration
|
||||
main() {}""";
|
||||
var source2 = """const native = 'xyz';
|
||||
@native @native
|
||||
$declaration
|
||||
main() {}""";
|
||||
|
||||
compileAndCheck(source, name, (compiler, element) {
|
||||
compileAndCheck(source2, name, (compiler, element) {
|
||||
compiler.enqueuer.resolution.queueIsClosed = false;
|
||||
Expect.equals(2, length(element.metadata));
|
||||
PartialMetadataAnnotation annotation1 = element.metadata.head;
|
||||
@@ -63,22 +62,22 @@ void checkAnnotation(String name, String declaration,
|
||||
Expect.stringEquals('xyz', value1.value.slowToString());
|
||||
Expect.stringEquals('xyz', value2.value.slowToString());
|
||||
|
||||
checkPosition(annotation1, annotation1.cachedNode, source, compiler);
|
||||
checkPosition(annotation2, annotation2.cachedNode, source, compiler);
|
||||
checkPosition(annotation1, annotation1.cachedNode, source2, compiler);
|
||||
checkPosition(annotation2, annotation2.cachedNode, source2, compiler);
|
||||
});
|
||||
|
||||
if (isTopLevelOnly) return;
|
||||
|
||||
// Ensure that a compile-time constant can be resolved from an
|
||||
// annotation.
|
||||
source = """const native = 'xyz';
|
||||
class Foo {
|
||||
@native
|
||||
$declaration
|
||||
}
|
||||
main() {}""";
|
||||
var source3 = """const native = 'xyz';
|
||||
class Foo {
|
||||
@native
|
||||
$declaration
|
||||
}
|
||||
main() {}""";
|
||||
|
||||
compileAndCheck(source, 'Foo', (compiler, element) {
|
||||
compileAndCheck(source3, 'Foo', (compiler, element) {
|
||||
compiler.enqueuer.resolution.queueIsClosed = false;
|
||||
Expect.equals(0, length(element.metadata));
|
||||
element.ensureResolved(compiler);
|
||||
@@ -90,19 +89,19 @@ void checkAnnotation(String name, String declaration,
|
||||
Constant value = annotation.value;
|
||||
Expect.stringEquals('xyz', value.value.slowToString());
|
||||
|
||||
checkPosition(annotation, annotation.cachedNode, source, compiler);
|
||||
checkPosition(annotation, annotation.cachedNode, source3, compiler);
|
||||
});
|
||||
|
||||
// Ensure that each repeated annotation has a unique instance of
|
||||
// [MetadataAnnotation].
|
||||
source = """const native = 'xyz';
|
||||
class Foo {
|
||||
@native @native
|
||||
$declaration
|
||||
}
|
||||
main() {}""";
|
||||
var source4 = """const native = 'xyz';
|
||||
class Foo {
|
||||
@native @native
|
||||
$declaration
|
||||
}
|
||||
main() {}""";
|
||||
|
||||
compileAndCheck(source, 'Foo', (compiler, element) {
|
||||
compileAndCheck(source4, 'Foo', (compiler, element) {
|
||||
compiler.enqueuer.resolution.queueIsClosed = false;
|
||||
Expect.equals(0, length(element.metadata));
|
||||
element.ensureResolved(compiler);
|
||||
@@ -122,8 +121,8 @@ void checkAnnotation(String name, String declaration,
|
||||
Expect.stringEquals('xyz', value1.value.slowToString());
|
||||
Expect.stringEquals('xyz', value2.value.slowToString());
|
||||
|
||||
checkPosition(annotation1, annotation1.cachedNode, source, compiler);
|
||||
checkPosition(annotation1, annotation2.cachedNode, source, compiler);
|
||||
checkPosition(annotation1, annotation1.cachedNode, source4, compiler);
|
||||
checkPosition(annotation1, annotation2.cachedNode, source4, compiler);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -156,21 +155,23 @@ void testLibraryTags() {
|
||||
var compiler = compilerFor(source, uri)
|
||||
..registerSource(partUri, partSource)
|
||||
..registerSource(libUri, libSource)
|
||||
..registerSource(async, 'class DeferredLibrary {}')
|
||||
..runCompiler(uri);
|
||||
compiler.enqueuer.resolution.queueIsClosed = false;
|
||||
LibraryElement element = compiler.libraries['$uri'];
|
||||
Expect.isNotNull(element, 'Cannot find $uri');
|
||||
..registerSource(async, 'class DeferredLibrary {}');
|
||||
|
||||
Link<MetadataAnnotation> metadata = extractMetadata(element);
|
||||
Expect.equals(1, length(metadata));
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
compiler.enqueuer.resolution.queueIsClosed = false;
|
||||
LibraryElement element = compiler.libraries['$uri'];
|
||||
Expect.isNotNull(element, 'Cannot find $uri');
|
||||
|
||||
PartialMetadataAnnotation annotation = metadata.head;
|
||||
annotation.ensureResolved(compiler);
|
||||
Constant value = annotation.value;
|
||||
Expect.stringEquals('xyz', value.value.slowToString());
|
||||
Link<MetadataAnnotation> metadata = extractMetadata(element);
|
||||
Expect.equals(1, length(metadata));
|
||||
|
||||
checkPosition(annotation, annotation.cachedNode, source, compiler);
|
||||
PartialMetadataAnnotation annotation = metadata.head;
|
||||
annotation.ensureResolved(compiler);
|
||||
Constant value = annotation.value;
|
||||
Expect.stringEquals('xyz', value.value.slowToString());
|
||||
|
||||
checkPosition(annotation, annotation.cachedNode, source, compiler);
|
||||
}));
|
||||
}
|
||||
|
||||
var source;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'memory_compiler.dart' show compilerFor;
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show
|
||||
Compiler;
|
||||
@@ -26,7 +28,7 @@ main() {
|
||||
testWithoutMirrorHelperLibrary(minify: false);
|
||||
}
|
||||
|
||||
Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
|
||||
Future<Compiler> runCompiler({useMirrorHelperLibrary: false, minify: false}) {
|
||||
List<String> options = ['--output-type=dart'];
|
||||
if (minify) {
|
||||
options.add('--minify');
|
||||
@@ -34,58 +36,59 @@ Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
|
||||
Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options);
|
||||
DartBackend backend = compiler.backend;
|
||||
backend.useMirrorHelperLibrary = useMirrorHelperLibrary;
|
||||
compiler.runCompiler(Uri.parse('memory:main.dart'));
|
||||
return compiler;
|
||||
return
|
||||
compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) => compiler);
|
||||
}
|
||||
|
||||
void testWithMirrorHelperLibrary({bool minify}) {
|
||||
Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: minify);
|
||||
asyncTest(() => runCompiler(useMirrorHelperLibrary: true, minify: minify).
|
||||
then((Compiler compiler) {
|
||||
DartBackend backend = compiler.backend;
|
||||
MirrorRenamer mirrorRenamer = backend.mirrorRenamer;
|
||||
Map<Node, String> renames = backend.renames;
|
||||
Map<String, SourceString> symbols = mirrorRenamer.symbols;
|
||||
|
||||
DartBackend backend = compiler.backend;
|
||||
MirrorRenamer mirrorRenamer = backend.mirrorRenamer;
|
||||
Map<Node, String> renames = backend.renames;
|
||||
Map<String, SourceString> symbols = mirrorRenamer.symbols;
|
||||
Expect.isFalse(null == backend.mirrorHelperLibrary);
|
||||
Expect.isFalse(null == backend.mirrorHelperGetNameFunction);
|
||||
|
||||
Expect.isFalse(null == backend.mirrorHelperLibrary);
|
||||
Expect.isFalse(null == backend.mirrorHelperGetNameFunction);
|
||||
|
||||
for (Node n in renames.keys) {
|
||||
if (symbols.containsKey(renames[n])) {
|
||||
if(n.toString() == 'getName') {
|
||||
Expect.equals(
|
||||
const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION),
|
||||
symbols[renames[n]]);
|
||||
} else {
|
||||
Expect.equals(n.toString(), symbols[renames[n]].stringValue);
|
||||
for (Node n in renames.keys) {
|
||||
if (symbols.containsKey(renames[n])) {
|
||||
if(n.toString() == 'getName') {
|
||||
Expect.equals(
|
||||
const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION),
|
||||
symbols[renames[n]]);
|
||||
} else {
|
||||
Expect.equals(n.toString(), symbols[renames[n]].stringValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String output = compiler.assembledCode;
|
||||
String getNameMatch = MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION;
|
||||
Iterable i = getNameMatch.allMatches(output);
|
||||
String output = compiler.assembledCode;
|
||||
String getNameMatch = MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION;
|
||||
Iterable i = getNameMatch.allMatches(output);
|
||||
|
||||
if (minify) {
|
||||
Expect.equals(0, i.length);
|
||||
} else {
|
||||
// Appears twice in code (defined & called).
|
||||
Expect.equals(2, i.length);
|
||||
}
|
||||
|
||||
if (minify) {
|
||||
Expect.equals(0, i.length);
|
||||
} else {
|
||||
// Appears twice in code (defined & called).
|
||||
Expect.equals(2, i.length);
|
||||
}
|
||||
|
||||
String mapMatch = 'const<String,SourceString>';
|
||||
i = mapMatch.allMatches(output);
|
||||
Expect.equals(1, i.length);
|
||||
String mapMatch = 'const<String,SourceString>';
|
||||
i = mapMatch.allMatches(output);
|
||||
Expect.equals(1, i.length);
|
||||
}));
|
||||
}
|
||||
|
||||
void testWithoutMirrorHelperLibrary({bool minify}) {
|
||||
Compiler compiler =
|
||||
runCompiler(useMirrorHelperLibrary: false, minify: minify);
|
||||
DartBackend backend = compiler.backend;
|
||||
asyncTest(() => runCompiler(useMirrorHelperLibrary: false, minify: minify).
|
||||
then((Compiler compiler) {
|
||||
DartBackend backend = compiler.backend;
|
||||
|
||||
Expect.equals(null, backend.mirrorHelperLibrary);
|
||||
Expect.equals(null, backend.mirrorHelperGetNameFunction);
|
||||
Expect.equals(null, backend.mirrorRenamer);
|
||||
Expect.equals(null, backend.mirrorHelperLibrary);
|
||||
Expect.equals(null, backend.mirrorHelperGetNameFunction);
|
||||
Expect.equals(null, backend.mirrorRenamer);
|
||||
}));
|
||||
}
|
||||
|
||||
const MEMORY_SOURCE_FILES = const <String, String> {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'memory_compiler.dart' show compilerFor;
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show
|
||||
Compiler;
|
||||
@@ -35,7 +37,7 @@ main() {
|
||||
testWithoutMirrorRenaming(minify: false);
|
||||
}
|
||||
|
||||
Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
|
||||
Future<Compiler> runCompiler({useMirrorHelperLibrary: false, minify: false}) {
|
||||
List<String> options = ['--output-type=dart'];
|
||||
if (minify) {
|
||||
options.add('--minify');
|
||||
@@ -43,42 +45,45 @@ Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
|
||||
Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options);
|
||||
DartBackend backend = compiler.backend;
|
||||
backend.useMirrorHelperLibrary = useMirrorHelperLibrary;
|
||||
compiler.runCompiler(Uri.parse('memory:main.dart'));
|
||||
return compiler;
|
||||
return
|
||||
compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) => compiler);
|
||||
}
|
||||
|
||||
void testWithMirrorRenaming({bool minify}) {
|
||||
Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: minify);
|
||||
asyncTest(() => runCompiler(useMirrorHelperLibrary: true, minify: minify).
|
||||
then((Compiler compiler) {
|
||||
|
||||
DartBackend backend = compiler.backend;
|
||||
MirrorRenamer mirrorRenamer = backend.mirrorRenamer;
|
||||
Map<Node, String> renames = backend.renames;
|
||||
Map<LibraryElement, String> imports = backend.imports;
|
||||
DartBackend backend = compiler.backend;
|
||||
MirrorRenamer mirrorRenamer = backend.mirrorRenamer;
|
||||
Map<Node, String> renames = backend.renames;
|
||||
Map<LibraryElement, String> imports = backend.imports;
|
||||
|
||||
Node getNameFunctionNode =
|
||||
backend.memberNodes.values.first.first.body.statements.nodes.head;
|
||||
Node getNameFunctionNode =
|
||||
backend.memberNodes.values.first.first.body.statements.nodes.head;
|
||||
|
||||
Expect.equals(renames[mirrorRenamer.mirrorHelperGetNameFunctionNode.name],
|
||||
renames[getNameFunctionNode.expression.selector]);
|
||||
Expect.equals("",
|
||||
renames[getNameFunctionNode.expression.receiver]);
|
||||
Expect.equals(1, imports.keys.length);
|
||||
Expect.equals(renames[mirrorRenamer.mirrorHelperGetNameFunctionNode.name],
|
||||
renames[getNameFunctionNode.expression.selector]);
|
||||
Expect.equals("",
|
||||
renames[getNameFunctionNode.expression.receiver]);
|
||||
Expect.equals(1, imports.keys.length);
|
||||
}));
|
||||
}
|
||||
|
||||
void testWithoutMirrorRenaming({bool minify}) {
|
||||
Compiler compiler =
|
||||
runCompiler(useMirrorHelperLibrary: false, minify: minify);
|
||||
asyncTest(() => runCompiler(useMirrorHelperLibrary: false, minify: minify).
|
||||
then((Compiler compiler) {
|
||||
|
||||
DartBackend backend = compiler.backend;
|
||||
Map<Node, String> renames = backend.renames;
|
||||
Map<LibraryElement, String> imports = backend.imports;
|
||||
DartBackend backend = compiler.backend;
|
||||
Map<Node, String> renames = backend.renames;
|
||||
Map<LibraryElement, String> imports = backend.imports;
|
||||
|
||||
Node getNameFunctionNode =
|
||||
backend.memberNodes.values.first.first.body.statements.nodes.head;
|
||||
Node getNameFunctionNode =
|
||||
backend.memberNodes.values.first.first.body.statements.nodes.head;
|
||||
|
||||
Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector));
|
||||
Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver));
|
||||
Expect.equals(1, imports.keys.length);
|
||||
Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector));
|
||||
Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver));
|
||||
Expect.equals(1, imports.keys.length);
|
||||
}));
|
||||
}
|
||||
|
||||
const MEMORY_SOURCE_FILES = const <String, String> {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'memory_compiler.dart' show compilerFor;
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show
|
||||
Compiler;
|
||||
@@ -20,7 +22,7 @@ main() {
|
||||
testNoUniqueMinification();
|
||||
}
|
||||
|
||||
Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
|
||||
Future<Compiler> runCompiler({useMirrorHelperLibrary: false, minify: false}) {
|
||||
List<String> options = ['--output-type=dart'];
|
||||
if (minify) {
|
||||
options.add('--minify');
|
||||
@@ -28,41 +30,46 @@ Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) {
|
||||
Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options);
|
||||
DartBackend backend = compiler.backend;
|
||||
backend.useMirrorHelperLibrary = useMirrorHelperLibrary;
|
||||
compiler.runCompiler(Uri.parse('memory:main.dart'));
|
||||
return compiler;
|
||||
return
|
||||
compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) => compiler);
|
||||
}
|
||||
|
||||
void testUniqueMinification() {
|
||||
Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: true);
|
||||
DartBackend backend = compiler.backend;
|
||||
MirrorRenamer mirrorRenamer = backend.mirrorRenamer;
|
||||
Map<Node, String> renames = backend.renames;
|
||||
Map<String, SourceString> symbols = mirrorRenamer.symbols;
|
||||
asyncTest(() => runCompiler(useMirrorHelperLibrary: true, minify: true).
|
||||
then((Compiler compiler) {
|
||||
DartBackend backend = compiler.backend;
|
||||
MirrorRenamer mirrorRenamer = backend.mirrorRenamer;
|
||||
Map<Node, String> renames = backend.renames;
|
||||
Map<String, SourceString> symbols = mirrorRenamer.symbols;
|
||||
|
||||
// Check that no two different source code names get the same mangled name,
|
||||
// with the exception of MirrorSystem.getName that gets renamed to the same
|
||||
// mangled name as the getNameHelper from _mirror_helper.dart.
|
||||
for (Node node in renames.keys) {
|
||||
Identifier identifier = node.asIdentifier();
|
||||
if (identifier != null) {
|
||||
SourceString source = identifier.source;
|
||||
if (mirrorRenamer.mirrorSystemGetNameNodes.first.selector == node)
|
||||
continue;
|
||||
if (symbols.containsKey(renames[node])) {
|
||||
print(node);
|
||||
Expect.equals(source, symbols[renames[node]]);
|
||||
// Check that no two different source code names get the same mangled name,
|
||||
// with the exception of MirrorSystem.getName that gets renamed to the same
|
||||
// mangled name as the getNameHelper from _mirror_helper.dart.
|
||||
for (Node node in renames.keys) {
|
||||
Identifier identifier = node.asIdentifier();
|
||||
if (identifier != null) {
|
||||
SourceString source = identifier.source;
|
||||
if (mirrorRenamer.mirrorSystemGetNameNodes.first.selector == node)
|
||||
continue;
|
||||
if (symbols.containsKey(renames[node])) {
|
||||
print(node);
|
||||
Expect.equals(source, symbols[renames[node]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void testNoUniqueMinification() {
|
||||
Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: true);
|
||||
DartBackend backend = compiler.backend;
|
||||
Map<Node, String> renames = backend.renames;
|
||||
asyncTest(() => runCompiler(useMirrorHelperLibrary: false, minify: true).
|
||||
then((Compiler compiler) {
|
||||
DartBackend backend = compiler.backend;
|
||||
Map<Node, String> renames = backend.renames;
|
||||
|
||||
// 'Foo' appears twice and 'invocation' and 'hest' get the same mangled name.
|
||||
Expect.equals(renames.values.toSet().length, renames.values.length - 2);
|
||||
// 'Foo' appears twice and 'invocation' and 'hest' get the same mangled
|
||||
// name.
|
||||
Expect.equals(renames.values.toSet().length, renames.values.length - 2);
|
||||
}));
|
||||
}
|
||||
|
||||
const MEMORY_SOURCE_FILES = const <String, String> {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// Test that tree-shaking hasn't been turned off.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'memory_source_file_helper.dart';
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart'
|
||||
@@ -20,8 +21,7 @@ main() {
|
||||
Uri libraryRoot = script.resolve('../../../sdk/');
|
||||
Uri packageRoot = script.resolve('./packages/');
|
||||
|
||||
MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES;
|
||||
var provider = new MemorySourceFileProvider();
|
||||
var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
|
||||
void diagnosticHandler(Uri uri, int begin, int end,
|
||||
String message, Diagnostic kind) {
|
||||
if (kind == Diagnostic.VERBOSE_INFO
|
||||
@@ -42,12 +42,13 @@ main() {
|
||||
libraryRoot,
|
||||
packageRoot,
|
||||
[]);
|
||||
compiler.run(Uri.parse('memory:main.dart'));
|
||||
Expect.isFalse(compiler.compilationFailed);
|
||||
Expect.isFalse(compiler.enqueuer.resolution.hasEnqueuedEverything);
|
||||
Expect.isFalse(compiler.enqueuer.codegen.hasEnqueuedEverything);
|
||||
Expect.isFalse(compiler.disableTypeInference);
|
||||
Expect.isFalse(compiler.backend.hasRetainedMetadata);
|
||||
asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) {
|
||||
Expect.isFalse(compiler.compilationFailed);
|
||||
Expect.isFalse(compiler.enqueuer.resolution.hasEnqueuedEverything);
|
||||
Expect.isFalse(compiler.enqueuer.codegen.hasEnqueuedEverything);
|
||||
Expect.isFalse(compiler.disableTypeInference);
|
||||
Expect.isFalse(compiler.backend.hasRetainedMetadata);
|
||||
}));
|
||||
}
|
||||
|
||||
const Map MEMORY_SOURCE_FILES = const {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
library dart2js.test.memory_source_file_helper;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'memory_compiler.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart';
|
||||
@@ -33,9 +34,9 @@ class Subclass<B> extends Class<B> {
|
||||
};
|
||||
|
||||
void main() {
|
||||
mirrorSystemFor(MEMORY_SOURCE_FILES).then(
|
||||
asyncTest(() => mirrorSystemFor(MEMORY_SOURCE_FILES).then(
|
||||
(MirrorSystem mirrors) => test(mirrors),
|
||||
onError: (e) => Expect.fail('$e'));
|
||||
onError: (e) => Expect.fail('$e')));
|
||||
}
|
||||
|
||||
void test(MirrorSystem mirrors) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'dart:async';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'dart:io';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
|
||||
@@ -14,15 +15,16 @@ import 'mock_compiler.dart';
|
||||
const String SOURCE = 'source';
|
||||
Uri SOURCE_URI = new Uri(scheme: SOURCE, path: SOURCE);
|
||||
|
||||
MirrorSystem createMirrorSystem(String source) {
|
||||
Future<MirrorSystem> createMirrorSystem(String source) {
|
||||
MockCompiler compiler = new MockCompiler(
|
||||
analyzeOnly: true,
|
||||
analyzeAll: true,
|
||||
preserveComments: true);
|
||||
compiler.registerSource(SOURCE_URI, source);
|
||||
compiler.librariesToAnalyzeWhenRun = <Uri>[SOURCE_URI];
|
||||
compiler.runCompiler(null);
|
||||
return new Dart2JsMirrorSystem(compiler);
|
||||
compiler.registerSource(SOURCE_URI, source);
|
||||
compiler.librariesToAnalyzeWhenRun = <Uri>[SOURCE_URI];
|
||||
return compiler.runCompiler(null).then((_) {
|
||||
return new Dart2JsMirrorSystem(compiler);
|
||||
});
|
||||
}
|
||||
|
||||
void validateDeclarationComment(String code,
|
||||
@@ -30,21 +32,22 @@ void validateDeclarationComment(String code,
|
||||
String trimmedText,
|
||||
bool isDocComment,
|
||||
List<String> declarationNames) {
|
||||
MirrorSystem mirrors = createMirrorSystem(code);
|
||||
LibraryMirror library = mirrors.libraries[SOURCE_URI];
|
||||
Expect.isNotNull(library);
|
||||
for (String declarationName in declarationNames) {
|
||||
DeclarationMirror declaration = library.members[declarationName];
|
||||
Expect.isNotNull(declaration);
|
||||
List<InstanceMirror> metadata = declaration.metadata;
|
||||
Expect.isNotNull(metadata);
|
||||
Expect.equals(1, metadata.length);
|
||||
Expect.isTrue(metadata[0] is CommentInstanceMirror);
|
||||
CommentInstanceMirror commentMetadata = metadata[0];
|
||||
Expect.equals(text, commentMetadata.text);
|
||||
Expect.equals(trimmedText, commentMetadata.trimmedText);
|
||||
Expect.equals(isDocComment, commentMetadata.isDocComment);
|
||||
}
|
||||
asyncTest(() => createMirrorSystem(code).then((mirrors) {
|
||||
LibraryMirror library = mirrors.libraries[SOURCE_URI];
|
||||
Expect.isNotNull(library);
|
||||
for (String declarationName in declarationNames) {
|
||||
DeclarationMirror declaration = library.members[declarationName];
|
||||
Expect.isNotNull(declaration);
|
||||
List<InstanceMirror> metadata = declaration.metadata;
|
||||
Expect.isNotNull(metadata);
|
||||
Expect.equals(1, metadata.length);
|
||||
Expect.isTrue(metadata[0] is CommentInstanceMirror);
|
||||
CommentInstanceMirror commentMetadata = metadata[0];
|
||||
Expect.equals(text, commentMetadata.text);
|
||||
Expect.equals(trimmedText, commentMetadata.trimmedText);
|
||||
Expect.equals(isDocComment, commentMetadata.isDocComment);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void testDeclarationComment(String declaration, List<String> declarationNames) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart';
|
||||
@@ -48,12 +49,13 @@ main() {
|
||||
var provider = new SourceFileProvider();
|
||||
var diagnosticHandler =
|
||||
new FormattingDiagnosticHandler(provider).diagnosticHandler;
|
||||
asyncStart();
|
||||
var result = analyze([inputUri], libUri, null,
|
||||
provider.readStringFromUri, diagnosticHandler,
|
||||
<String>['--preserve-comments']);
|
||||
result.then((MirrorSystem mirrors) {
|
||||
test(mirrors);
|
||||
});
|
||||
}).whenComplete(() => asyncEnd());
|
||||
}
|
||||
|
||||
void test(MirrorSystem mirrors) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
library dart2js.test.mirrors_used_test;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
import 'memory_compiler.dart' show
|
||||
compilerFor;
|
||||
@@ -35,87 +36,88 @@ void expectOnlyVerboseInfo(Uri uri, int begin, int end, String message, kind) {
|
||||
void main() {
|
||||
Compiler compiler = compilerFor(
|
||||
MEMORY_SOURCE_FILES, diagnosticHandler: expectOnlyVerboseInfo);
|
||||
compiler.runCompiler(Uri.parse('memory:main.dart'));
|
||||
asyncTest(() => compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) {
|
||||
print('');
|
||||
List generatedCode =
|
||||
Elements.sortedByPosition(compiler.enqueuer.codegen.generatedCode.keys);
|
||||
for (var element in generatedCode) {
|
||||
print(element);
|
||||
}
|
||||
print('');
|
||||
|
||||
print('');
|
||||
List generatedCode =
|
||||
Elements.sortedByPosition(compiler.enqueuer.codegen.generatedCode.keys);
|
||||
for (var element in generatedCode) {
|
||||
print(element);
|
||||
}
|
||||
print('');
|
||||
// This assertion can fail for two reasons:
|
||||
// 1. Too many elements retained for reflection.
|
||||
// 2. Some code was refactored, and there are more methods.
|
||||
// Either situation could be problematic, but in situation 2, it is often
|
||||
// acceptable to increase [expectedMethodCount] a little.
|
||||
int expectedMethodCount = 322;
|
||||
Expect.isTrue(
|
||||
generatedCode.length <= expectedMethodCount,
|
||||
'Too many compiled methods: '
|
||||
'${generatedCode.length} > $expectedMethodCount');
|
||||
|
||||
// This assertion can fail for two reasons:
|
||||
// 1. Too many elements retained for reflection.
|
||||
// 2. Some code was refactored, and there are more methods.
|
||||
// Either situation could be problematic, but in situation 2, it is often
|
||||
// acceptable to increase [expectedMethodCount] a little.
|
||||
int expectedMethodCount = 322;
|
||||
Expect.isTrue(
|
||||
generatedCode.length <= expectedMethodCount,
|
||||
'Too many compiled methods: '
|
||||
'${generatedCode.length} > $expectedMethodCount');
|
||||
// The following names should be retained:
|
||||
List expectedNames = [
|
||||
'Foo', // The name of class Foo.
|
||||
r'Foo$', // The name of class Foo's constructor.
|
||||
'Foo_staticMethod', // The name of Foo.staticMethod.
|
||||
r'get$field', // The (getter) name of Foo.field.
|
||||
r'instanceMethod$0']; // The name of Foo.instanceMethod.
|
||||
Set recordedNames = new Set()
|
||||
..addAll(compiler.backend.emitter.recordedMangledNames)
|
||||
..addAll(compiler.backend.emitter.mangledFieldNames.keys)
|
||||
..addAll(compiler.backend.emitter.mangledGlobalFieldNames.keys);
|
||||
Expect.setEquals(new Set.from(expectedNames), recordedNames);
|
||||
|
||||
// The following names should be retained:
|
||||
List expectedNames = [
|
||||
'Foo', // The name of class Foo.
|
||||
r'Foo$', // The name of class Foo's constructor.
|
||||
'Foo_staticMethod', // The name of Foo.staticMethod.
|
||||
r'get$field', // The (getter) name of Foo.field.
|
||||
r'instanceMethod$0']; // The name of Foo.instanceMethod.
|
||||
Set recordedNames = new Set()
|
||||
..addAll(compiler.backend.emitter.recordedMangledNames)
|
||||
..addAll(compiler.backend.emitter.mangledFieldNames.keys)
|
||||
..addAll(compiler.backend.emitter.mangledGlobalFieldNames.keys);
|
||||
Expect.setEquals(new Set.from(expectedNames), recordedNames);
|
||||
|
||||
for (var library in compiler.libraries.values) {
|
||||
library.forEachLocalMember((member) {
|
||||
if (library == compiler.mainApp
|
||||
&& member.name == const SourceString('Foo')) {
|
||||
Expect.isTrue(
|
||||
compiler.backend.isNeededForReflection(member), '$member');
|
||||
member.forEachLocalMember((classMember) {
|
||||
for (var library in compiler.libraries.values) {
|
||||
library.forEachLocalMember((member) {
|
||||
if (library == compiler.mainApp
|
||||
&& member.name == const SourceString('Foo')) {
|
||||
Expect.isTrue(
|
||||
compiler.backend.isNeededForReflection(classMember),
|
||||
'$classMember');
|
||||
});
|
||||
} else {
|
||||
Expect.isFalse(
|
||||
compiler.backend.isNeededForReflection(member), '$member');
|
||||
compiler.backend.isNeededForReflection(member), '$member');
|
||||
member.forEachLocalMember((classMember) {
|
||||
Expect.isTrue(
|
||||
compiler.backend.isNeededForReflection(classMember),
|
||||
'$classMember');
|
||||
});
|
||||
} else {
|
||||
Expect.isFalse(
|
||||
compiler.backend.isNeededForReflection(member), '$member');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// There should at least be three metadata constants:
|
||||
// 1. The type literal 'Foo'.
|
||||
// 2. The list 'const [Foo]'.
|
||||
// 3. The constructed constant for 'MirrorsUsed'.
|
||||
Expect.isTrue(compiler.metadataHandler.compiledConstants.length >= 3);
|
||||
|
||||
// Make sure that most of the metadata constants aren't included in the
|
||||
// generated code.
|
||||
for (Constant constant in compiler.metadataHandler.compiledConstants) {
|
||||
if (constant is TypeConstant && '${constant.representedType}' == 'Foo') {
|
||||
// The type literal 'Foo' is retained as a constant because it is being
|
||||
// passed to reflectClass.
|
||||
continue;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// There should at least be three metadata constants:
|
||||
// 1. The type literal 'Foo'.
|
||||
// 2. The list 'const [Foo]'.
|
||||
// 3. The constructed constant for 'MirrorsUsed'.
|
||||
Expect.isTrue(compiler.metadataHandler.compiledConstants.length >= 3);
|
||||
|
||||
// Make sure that most of the metadata constants aren't included in the
|
||||
// generated code.
|
||||
for (Constant constant in compiler.metadataHandler.compiledConstants) {
|
||||
if (constant is TypeConstant && '${constant.representedType}' == 'Foo') {
|
||||
// The type literal 'Foo' is retained as a constant because it is being
|
||||
// passed to reflectClass.
|
||||
continue;
|
||||
Expect.isFalse(
|
||||
compiler.constantHandler.compiledConstants.contains(constant),
|
||||
'$constant');
|
||||
}
|
||||
Expect.isFalse(
|
||||
compiler.constantHandler.compiledConstants.contains(constant),
|
||||
'$constant');
|
||||
}
|
||||
|
||||
// The type literal 'Foo' is both used as metadata, and as a plain value in
|
||||
// the program. Make sure that it isn't duplicated.
|
||||
int fooConstantCount = 0;
|
||||
for (Constant constant in compiler.metadataHandler.compiledConstants) {
|
||||
if (constant is TypeConstant && '${constant.representedType}' == 'Foo') {
|
||||
fooConstantCount++;
|
||||
// The type literal 'Foo' is both used as metadata, and as a plain value in
|
||||
// the program. Make sure that it isn't duplicated.
|
||||
int fooConstantCount = 0;
|
||||
for (Constant constant in compiler.metadataHandler.compiledConstants) {
|
||||
if (constant is TypeConstant && '${constant.representedType}' == 'Foo') {
|
||||
fooConstantCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Expect.equals(
|
||||
1, fooConstantCount, "The type literal 'Foo' is duplicated or missing.");
|
||||
Expect.equals(
|
||||
1, fooConstantCount,
|
||||
"The type literal 'Foo' is duplicated or missing.");
|
||||
}));
|
||||
}
|
||||
|
||||
const MEMORY_SOURCE_FILES = const <String, String> {
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
// Copyright (c) 2013, 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.
|
||||
|
||||
// Test that the compiler can handle imports when package root has not been set.
|
||||
|
||||
library dart2js.test.missing_file;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'memory_source_file_helper.dart';
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart'
|
||||
show NullSink;
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/compiler.dart'
|
||||
show DiagnosticHandler, Diagnostic;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart';
|
||||
|
||||
const MEMORY_SOURCE_FILES = const {
|
||||
'main.dart': '''
|
||||
|
||||
import 'foo.dart';
|
||||
|
||||
main() {}
|
||||
''',
|
||||
};
|
||||
|
||||
void runCompiler(Uri main, String expectedMessage) {
|
||||
Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script));
|
||||
Uri libraryRoot = script.resolve('../../../sdk/');
|
||||
|
||||
var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
|
||||
var handler = new FormattingDiagnosticHandler(provider);
|
||||
var errors = [];
|
||||
|
||||
void diagnosticHandler(Uri uri, int begin, int end, String message,
|
||||
Diagnostic kind) {
|
||||
if (kind == Diagnostic.ERROR) {
|
||||
errors.add(message);
|
||||
}
|
||||
handler(uri, begin, end, message, kind);
|
||||
}
|
||||
|
||||
|
||||
EventSink<String> outputProvider(String name, String extension) {
|
||||
if (name != '') throw 'Attempt to output file "$name.$extension"';
|
||||
return new NullSink('$name.$extension');
|
||||
}
|
||||
|
||||
Compiler compiler = new Compiler(provider,
|
||||
outputProvider,
|
||||
diagnosticHandler,
|
||||
libraryRoot,
|
||||
null,
|
||||
[]);
|
||||
|
||||
asyncTest(() => compiler.run(main).then((_) {
|
||||
Expect.equals(1, errors.length);
|
||||
Expect.equals(expectedMessage,
|
||||
errors[0]);
|
||||
}));
|
||||
}
|
||||
|
||||
void main() {
|
||||
runCompiler(Uri.parse('memory:main.dart'),
|
||||
"Error: Can't read 'memory:foo.dart' "
|
||||
"(No such file memory:foo.dart).");
|
||||
runCompiler(Uri.parse('memory:foo.dart'),
|
||||
"Error: Can't read 'memory:foo.dart' "
|
||||
"(No such file memory:foo.dart).");
|
||||
runCompiler(Uri.parse('dart:foo'),
|
||||
'Error: Library not found "dart:foo".');
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
library mock_compiler;
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/compiler.dart' as api;
|
||||
@@ -238,13 +239,18 @@ class MockCompiler extends Compiler {
|
||||
analyzeOnly: analyzeOnly,
|
||||
emitJavaScript: emitJavaScript,
|
||||
preserveComments: preserveComments) {
|
||||
coreLibrary = createLibrary("core", coreSource);
|
||||
coreLibrary = deprecatedFutureValue(createLibrary("core", coreSource));
|
||||
|
||||
// We need to set the assert method to avoid calls with a 'null'
|
||||
// target being interpreted as a call to assert.
|
||||
jsHelperLibrary = createLibrary("helper", helperSource);
|
||||
foreignLibrary = createLibrary("foreign", FOREIGN_LIBRARY);
|
||||
interceptorsLibrary = createLibrary("interceptors", interceptorsSource);
|
||||
isolateHelperLibrary = createLibrary("isolate_helper", isolateHelperSource);
|
||||
jsHelperLibrary = deprecatedFutureValue(
|
||||
createLibrary("helper", helperSource));
|
||||
foreignLibrary = deprecatedFutureValue(
|
||||
createLibrary("foreign", FOREIGN_LIBRARY));
|
||||
interceptorsLibrary = deprecatedFutureValue(
|
||||
createLibrary("interceptors", interceptorsSource));
|
||||
isolateHelperLibrary = deprecatedFutureValue(
|
||||
createLibrary("isolate_helper", isolateHelperSource));
|
||||
|
||||
// Set up the library imports.
|
||||
importHelperLibrary(coreLibrary);
|
||||
@@ -282,7 +288,7 @@ class MockCompiler extends Compiler {
|
||||
* Used internally to create a library from a source text. The created library
|
||||
* is fixed to export its top-level declarations.
|
||||
*/
|
||||
LibraryElement createLibrary(String name, String source) {
|
||||
Future<LibraryElement> createLibrary(String name, String source) {
|
||||
Uri uri = new Uri(scheme: "dart", path: name);
|
||||
var script = new Script(uri, new MockFile(source));
|
||||
var library = new LibraryElementX(script);
|
||||
@@ -291,7 +297,7 @@ class MockCompiler extends Compiler {
|
||||
library.setExports(library.localScope.values.toList());
|
||||
registerSource(uri, source);
|
||||
libraries.putIfAbsent(uri.toString(), () => library);
|
||||
return library;
|
||||
return new Future.value(library);
|
||||
}
|
||||
|
||||
void reportWarning(Node node, var message) {
|
||||
@@ -377,12 +383,14 @@ class MockCompiler extends Compiler {
|
||||
parseUnit(text, this, library, registerSource);
|
||||
}
|
||||
|
||||
void scanBuiltinLibraries() {
|
||||
Future scanBuiltinLibraries() {
|
||||
// Do nothing. The mock core library is already handled in the constructor.
|
||||
return new Future.value();
|
||||
}
|
||||
|
||||
LibraryElement scanBuiltinLibrary(String name) {
|
||||
Future<LibraryElement> scanBuiltinLibrary(String name) {
|
||||
// Do nothing. The mock core library is already handled in the constructor.
|
||||
return new Future.value();
|
||||
}
|
||||
|
||||
Uri translateResolvedUri(LibraryElement importingLibrary,
|
||||
@@ -391,10 +399,10 @@ class MockCompiler extends Compiler {
|
||||
// The mock library doesn't need any patches.
|
||||
Uri resolvePatchUri(String dartLibraryName) => null;
|
||||
|
||||
Script readScript(Uri uri, [Node node]) {
|
||||
Future<Script> readScript(Uri uri, [Element element, Node node]) {
|
||||
SourceFile sourceFile = sourceFiles[uri.toString()];
|
||||
if (sourceFile == null) throw new ArgumentError(uri);
|
||||
return new Script(uri, sourceFile);
|
||||
return new Future.value(new Script(uri, sourceFile));
|
||||
}
|
||||
|
||||
Element lookupElementIn(ScopeContainerElement container, name) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST = r"""
|
||||
@@ -17,7 +18,7 @@ main() {
|
||||
""";
|
||||
|
||||
main() {
|
||||
String generated = compileAll(TEST);
|
||||
Expect.isTrue(
|
||||
generated.contains('A: {"": "Object;", static:'));
|
||||
asyncTest(() => compileAll(TEST).then((generated) {
|
||||
Expect.isTrue(generated.contains('A: {"": "Object;", static:'));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'compiler_helper.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
const String CODE = """
|
||||
var x = 0;
|
||||
@@ -21,8 +22,9 @@ main() {
|
||||
""";
|
||||
|
||||
main() {
|
||||
String generated = compileAll(CODE);
|
||||
RegExp regexp = new RegExp(r'A\$0: function');
|
||||
Iterator<Match> matches = regexp.allMatches(generated).iterator;
|
||||
checkNumberOfMatches(matches, 1);
|
||||
asyncTest(() => compileAll(CODE).then((generated) {
|
||||
RegExp regexp = new RegExp(r'A\$0: function');
|
||||
Iterator<Match> matches = regexp.allMatches(generated).iterator;
|
||||
checkNumberOfMatches(matches, 1);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// 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.
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String CODE = """
|
||||
@@ -15,8 +16,9 @@ main() {
|
||||
""";
|
||||
|
||||
main() {
|
||||
String generated = compileAll(CODE);
|
||||
RegExp regexp = new RegExp(r'\A: {"": "[A-za-z]+;"');
|
||||
Iterator<Match> matches = regexp.allMatches(generated).iterator;
|
||||
checkNumberOfMatches(matches, 1);
|
||||
asyncTest(() => compileAll(CODE).then((generated) {
|
||||
RegExp regexp = new RegExp(r'\A: {"": "[A-za-z]+;"');
|
||||
Iterator<Match> matches = regexp.allMatches(generated).iterator;
|
||||
checkNumberOfMatches(matches, 1);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// 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.
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST = r"""
|
||||
@@ -28,8 +29,9 @@ baz(a) {
|
||||
""";
|
||||
|
||||
main() {
|
||||
String generated = compileAll(TEST);
|
||||
RegExp regexp = new RegExp('foo\\\$1\\\$a: function');
|
||||
Iterator<Match> matches = regexp.allMatches(generated).iterator;
|
||||
checkNumberOfMatches(matches, 1);
|
||||
asyncTest(() => compileAll(TEST).then((generated) {
|
||||
RegExp regexp = new RegExp('foo\\\$1\\\$a: function');
|
||||
Iterator<Match> matches = regexp.allMatches(generated).iterator;
|
||||
checkNumberOfMatches(matches, 1);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
library dart2js.test.package_root;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'memory_source_file_helper.dart';
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart'
|
||||
@@ -33,8 +34,7 @@ void runCompiler(Uri main) {
|
||||
Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script));
|
||||
Uri libraryRoot = script.resolve('../../../sdk/');
|
||||
|
||||
MemorySourceFileProvider.MEMORY_SOURCE_FILES = MEMORY_SOURCE_FILES;
|
||||
var provider = new MemorySourceFileProvider();
|
||||
var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
|
||||
var handler = new FormattingDiagnosticHandler(provider);
|
||||
var errors = [];
|
||||
|
||||
@@ -52,18 +52,19 @@ void runCompiler(Uri main) {
|
||||
return new NullSink('$name.$extension');
|
||||
}
|
||||
|
||||
Compiler compiler = new Compiler(provider.readStringFromUri,
|
||||
Compiler compiler = new Compiler(provider,
|
||||
outputProvider,
|
||||
diagnosticHandler,
|
||||
libraryRoot,
|
||||
null,
|
||||
[]);
|
||||
|
||||
compiler.run(main);
|
||||
Expect.equals(1, errors.length);
|
||||
Expect.equals('Error: Cannot resolve "package:foo/foo.dart". '
|
||||
'Package root has not been set.',
|
||||
errors[0]);
|
||||
asyncTest(() => compiler.run(main).then((_) {
|
||||
Expect.equals(1, errors.length);
|
||||
Expect.equals('Error: Cannot resolve "package:foo/foo.dart". '
|
||||
'Package root has not been set.',
|
||||
errors[0]);
|
||||
}));
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
library part_of_test;
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'mock_compiler.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart'
|
||||
show MessageKind;
|
||||
@@ -25,13 +26,16 @@ void main() {
|
||||
compiler.registerSource(libraryUri, LIBRARY_SOURCE);
|
||||
compiler.registerSource(partUri, PART_SOURCE);
|
||||
|
||||
compiler.libraryLoader.loadLibrary(libraryUri, null, libraryUri);
|
||||
print('errors: ${compiler.errors}');
|
||||
print('warnings: ${compiler.warnings}');
|
||||
Expect.isTrue(compiler.errors.isEmpty);
|
||||
Expect.equals(1, compiler.warnings.length);
|
||||
Expect.equals(MessageKind.LIBRARY_NAME_MISMATCH,
|
||||
compiler.warnings[0].message.kind);
|
||||
Expect.equals('foo',
|
||||
compiler.warnings[0].message.arguments['libraryName'].toString());
|
||||
asyncTest(() =>
|
||||
compiler.libraryLoader.loadLibrary(libraryUri, null, libraryUri).
|
||||
then((_) {
|
||||
print('errors: ${compiler.errors}');
|
||||
print('warnings: ${compiler.warnings}');
|
||||
Expect.isTrue(compiler.errors.isEmpty);
|
||||
Expect.equals(1, compiler.warnings.length);
|
||||
Expect.equals(MessageKind.LIBRARY_NAME_MISMATCH,
|
||||
compiler.warnings[0].message.kind);
|
||||
Expect.equals('foo',
|
||||
compiler.warnings[0].message.arguments['libraryName'].toString());
|
||||
}));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'mock_compiler.dart';
|
||||
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart';
|
||||
@@ -68,8 +69,9 @@ void analyze(String text, [expectedWarnings]) {
|
||||
''';
|
||||
Uri uri = Uri.parse('src:public');
|
||||
compiler.registerSource(uri, source);
|
||||
compiler.runCompiler(uri);
|
||||
compareWarningKinds(text, expectedWarnings, compiler.warnings);
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
compareWarningKinds(text, expectedWarnings, compiler.warnings);
|
||||
}));
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
library reexport_handled_test;
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'mock_compiler.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart'
|
||||
show Element,
|
||||
@@ -28,19 +29,21 @@ void main() {
|
||||
compiler.registerSource(reexportingLibraryUri, REEXPORTING_LIBRARY_SOURCE);
|
||||
|
||||
// Load exporting library before the reexporting library.
|
||||
var exportingLibrary = compiler.libraryLoader.loadLibrary(
|
||||
exportingLibraryUri, null, exportingLibraryUri);
|
||||
Expect.isTrue(exportingLibrary.exportsHandled);
|
||||
var foo = findInExports(exportingLibrary, 'foo');
|
||||
Expect.isNotNull(foo);
|
||||
Expect.isTrue(foo.isField());
|
||||
asyncTest(() => compiler.libraryLoader.loadLibrary(
|
||||
exportingLibraryUri, null, exportingLibraryUri).then((exportingLibrary) {
|
||||
Expect.isTrue(exportingLibrary.exportsHandled);
|
||||
var foo = findInExports(exportingLibrary, 'foo');
|
||||
Expect.isNotNull(foo);
|
||||
Expect.isTrue(foo.isField());
|
||||
|
||||
// Load reexporting library when exports are handled on the exporting library.
|
||||
var reexportingLibrary = compiler.libraryLoader.loadLibrary(
|
||||
reexportingLibraryUri, null, reexportingLibraryUri);
|
||||
foo = findInExports(reexportingLibrary, 'foo');
|
||||
Expect.isNotNull(foo);
|
||||
Expect.isTrue(foo.isField());
|
||||
// Load reexporting library when exports are handled on the exporting library.
|
||||
return compiler.libraryLoader.loadLibrary(
|
||||
reexportingLibraryUri, null, reexportingLibraryUri);
|
||||
}).then((reexportingLibrary) {
|
||||
var foo = findInExports(reexportingLibrary, 'foo');
|
||||
Expect.isNotNull(foo);
|
||||
Expect.isTrue(foo.isField());
|
||||
}));
|
||||
}
|
||||
|
||||
Element findInExports(LibraryElement library, String name) {
|
||||
|
||||
@@ -5,13 +5,16 @@
|
||||
// Regression test for http://dartbug.com/10231.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'codegen_helper.dart';
|
||||
|
||||
void main() {
|
||||
var code = generate(SOURCE)['test'];
|
||||
Expect.isNotNull(code);
|
||||
Expect.equals(0, new RegExp('add').allMatches(code).length);
|
||||
Expect.equals(3, new RegExp('\\+').allMatches(code).length);
|
||||
asyncTest(() => generate(SOURCE).then((result) {
|
||||
var code = result['test'];
|
||||
Expect.isNotNull(code);
|
||||
Expect.equals(0, new RegExp('add').allMatches(code).length);
|
||||
Expect.equals(3, new RegExp('\\+').allMatches(code).length);
|
||||
}));
|
||||
}
|
||||
|
||||
const String SOURCE = """
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// needed by the backend.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -94,8 +95,9 @@ main() {
|
||||
void test(String code, void check(Compiler compiler)) {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(code, uri);
|
||||
compiler.runCompiler(uri);
|
||||
check(compiler);
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
check(compiler);
|
||||
}));
|
||||
}
|
||||
|
||||
void testHasRuntimeType(String code) {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import 'dart:async';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'dart:collection';
|
||||
|
||||
import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution.dart";
|
||||
@@ -841,11 +843,12 @@ List<String> asSortedStrings(Link link) {
|
||||
return result;
|
||||
}
|
||||
|
||||
compileScript(String source) {
|
||||
Future compileScript(String source) {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
MockCompiler compiler = compilerFor(source, uri);
|
||||
compiler.runCompiler(uri);
|
||||
return compiler;
|
||||
return compiler.runCompiler(uri).then((_) {
|
||||
return compiler;
|
||||
});
|
||||
}
|
||||
|
||||
checkMemberResolved(compiler, className, memberName) {
|
||||
@@ -858,9 +861,9 @@ checkMemberResolved(compiler, className, memberName) {
|
||||
|
||||
testToString() {
|
||||
final script = r"class C { toString() => 'C'; } main() { '${new C()}'; }";
|
||||
final compiler = compileScript(script);
|
||||
|
||||
checkMemberResolved(compiler, 'C', buildSourceString('toString'));
|
||||
asyncTest(() => compileScript(script).then((compiler) {
|
||||
checkMemberResolved(compiler, 'C', buildSourceString('toString'));
|
||||
}));
|
||||
}
|
||||
|
||||
operatorName(op, isUnary) {
|
||||
@@ -874,10 +877,10 @@ testIndexedOperator() {
|
||||
operator[]=(ix, v) {}
|
||||
}
|
||||
main() { var c = new C(); c[0]++; }""";
|
||||
final compiler = compileScript(script);
|
||||
|
||||
checkMemberResolved(compiler, 'C', operatorName('[]', false));
|
||||
checkMemberResolved(compiler, 'C', operatorName('[]=', false));
|
||||
asyncTest(() => compileScript(script).then((compiler) {
|
||||
checkMemberResolved(compiler, 'C', operatorName('[]', false));
|
||||
checkMemberResolved(compiler, 'C', operatorName('[]=', false));
|
||||
}));
|
||||
}
|
||||
|
||||
testIncrementsAndDecrements() {
|
||||
@@ -896,12 +899,12 @@ testIncrementsAndDecrements() {
|
||||
var d = new D();
|
||||
--d;
|
||||
}""";
|
||||
final compiler = compileScript(script);
|
||||
|
||||
checkMemberResolved(compiler, 'A', operatorName('+', false));
|
||||
checkMemberResolved(compiler, 'B', operatorName('+', false));
|
||||
checkMemberResolved(compiler, 'C', operatorName('-', false));
|
||||
checkMemberResolved(compiler, 'D', operatorName('-', false));
|
||||
asyncTest(() => compileScript(script).then((compiler) {
|
||||
checkMemberResolved(compiler, 'A', operatorName('+', false));
|
||||
checkMemberResolved(compiler, 'B', operatorName('+', false));
|
||||
checkMemberResolved(compiler, 'C', operatorName('-', false));
|
||||
checkMemberResolved(compiler, 'D', operatorName('-', false));
|
||||
}));
|
||||
}
|
||||
|
||||
testOverrideHashCodeCheck() {
|
||||
@@ -916,9 +919,10 @@ testOverrideHashCodeCheck() {
|
||||
main() {
|
||||
new A() == new B();
|
||||
}""";
|
||||
final compiler = compileScript(script);
|
||||
Expect.equals(1, compiler.warnings.length);
|
||||
Expect.equals(MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE,
|
||||
compiler.warnings[0].message.kind);
|
||||
Expect.equals(0, compiler.errors.length);
|
||||
asyncTest(() => compileScript(script).then((compiler) {
|
||||
Expect.equals(1, compiler.warnings.length);
|
||||
Expect.equals(MessageKind.OVERRIDE_EQUALS_NOT_HASH_CODE,
|
||||
compiler.warnings[0].message.kind);
|
||||
Expect.equals(0, compiler.errors.length);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// field is being gvn'ed.
|
||||
|
||||
import 'compiler_helper.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
const String TEST = r"""
|
||||
class A {
|
||||
@@ -25,11 +26,12 @@ main() {
|
||||
""";
|
||||
|
||||
main() {
|
||||
String generated = compileAll(TEST);
|
||||
RegExp regexp = new RegExp('foo\\\$0\\\$bailout');
|
||||
Iterator matches = regexp.allMatches(generated).iterator;
|
||||
asyncTest(() => compileAll(TEST).then((generated) {
|
||||
RegExp regexp = new RegExp('foo\\\$0\\\$bailout');
|
||||
Iterator matches = regexp.allMatches(generated).iterator;
|
||||
|
||||
// We check that there is only one call to the bailout method.
|
||||
// One match for the call, one for the definition.
|
||||
checkNumberOfMatches(matches, 2);
|
||||
// We check that there is only one call to the bailout method.
|
||||
// One match for the call, one for the definition.
|
||||
checkNumberOfMatches(matches, 2);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST = """
|
||||
@@ -57,22 +58,23 @@ main() {
|
||||
void main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
|
||||
checkReturn(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
Expect.equals(type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
checkReturn(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
Expect.equals(type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
|
||||
var subclassOfInterceptor =
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
|
||||
var subclassOfInterceptor =
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
|
||||
|
||||
checkReturn('returnDyn1', subclassOfInterceptor);
|
||||
checkReturn('returnDyn2', subclassOfInterceptor);
|
||||
checkReturn('returnDyn3', subclassOfInterceptor);
|
||||
checkReturn('returnDyn4', compiler.typesTask.dynamicType.nonNullable());
|
||||
checkReturn('returnDyn5', compiler.typesTask.dynamicType.nonNullable());
|
||||
checkReturn('returnDyn6', compiler.typesTask.dynamicType.nonNullable());
|
||||
checkReturn('returnDyn1', subclassOfInterceptor);
|
||||
checkReturn('returnDyn2', subclassOfInterceptor);
|
||||
checkReturn('returnDyn3', subclassOfInterceptor);
|
||||
checkReturn('returnDyn4', compiler.typesTask.dynamicType.nonNullable());
|
||||
checkReturn('returnDyn5', compiler.typesTask.dynamicType.nonNullable());
|
||||
checkReturn('returnDyn6', compiler.typesTask.dynamicType.nonNullable());
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST = """
|
||||
@@ -97,22 +98,23 @@ main() {
|
||||
void main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
|
||||
checkReturn(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
Expect.equals(type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
checkReturn(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
Expect.equals(type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
|
||||
checkReturn('returnInt1', compiler.typesTask.intType);
|
||||
checkReturn('returnInt2', compiler.typesTask.intType.nullable());
|
||||
checkReturn('returnInt3', compiler.typesTask.intType);
|
||||
checkReturn('returnInt4', compiler.typesTask.intType);
|
||||
checkReturn('returnInt1', compiler.typesTask.intType);
|
||||
checkReturn('returnInt2', compiler.typesTask.intType.nullable());
|
||||
checkReturn('returnInt3', compiler.typesTask.intType);
|
||||
checkReturn('returnInt4', compiler.typesTask.intType);
|
||||
|
||||
checkReturn('returnDyn1', compiler.typesTask.dynamicType);
|
||||
checkReturn('returnDyn2', compiler.typesTask.dynamicType);
|
||||
checkReturn('returnDyn3', compiler.typesTask.dynamicType);
|
||||
checkReturn('returnNum1', compiler.typesTask.numType);
|
||||
checkReturn('returnDyn1', compiler.typesTask.dynamicType);
|
||||
checkReturn('returnDyn2', compiler.typesTask.dynamicType);
|
||||
checkReturn('returnDyn3', compiler.typesTask.dynamicType);
|
||||
checkReturn('returnNum1', compiler.typesTask.numType);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// infering types for fields.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -26,15 +27,16 @@ main() {
|
||||
void main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
|
||||
checkFieldTypeInClass(String className, String fieldName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(fieldName));
|
||||
Expect.equals(type, typesInferrer.getTypeOfElement(element));
|
||||
}
|
||||
checkFieldTypeInClass(String className, String fieldName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(fieldName));
|
||||
Expect.equals(type, typesInferrer.getTypeOfElement(element));
|
||||
}
|
||||
|
||||
checkFieldTypeInClass('A', 'intField', compiler.typesTask.intType);
|
||||
checkFieldTypeInClass('A', 'stringField', compiler.typesTask.stringType);
|
||||
checkFieldTypeInClass('A', 'intField', compiler.typesTask.intType);
|
||||
checkFieldTypeInClass('A', 'stringField', compiler.typesTask.stringType);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// Test that we are analyzing field parameters correctly.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -25,16 +26,17 @@ main() {
|
||||
void main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
|
||||
checkFieldTypeInClass(String className, String fieldName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(fieldName));
|
||||
Expect.equals(type,
|
||||
typesInferrer.getTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
checkFieldTypeInClass(String className, String fieldName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(fieldName));
|
||||
Expect.equals(type,
|
||||
typesInferrer.getTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
|
||||
checkFieldTypeInClass('A', 'dynamicField',
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'));
|
||||
checkFieldTypeInClass('A', 'dynamicField',
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -28,20 +29,21 @@ main() {
|
||||
void main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
|
||||
checkFieldTypeInClass(String className, String fieldName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(fieldName));
|
||||
Expect.equals(type,
|
||||
typesInferrer.getTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
checkFieldTypeInClass(String className, String fieldName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(fieldName));
|
||||
Expect.equals(type,
|
||||
typesInferrer.getTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
|
||||
checkFieldTypeInClass('A', 'intField', compiler.typesTask.intType);
|
||||
checkFieldTypeInClass('A', 'giveUpField1',
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'));
|
||||
checkFieldTypeInClass('A', 'giveUpField2',
|
||||
compiler.typesTask.dynamicType.nonNullable());
|
||||
checkFieldTypeInClass('A', 'fieldParameter', compiler.typesTask.intType);
|
||||
checkFieldTypeInClass('A', 'intField', compiler.typesTask.intType);
|
||||
checkFieldTypeInClass('A', 'giveUpField1',
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'));
|
||||
checkFieldTypeInClass('A', 'giveUpField2',
|
||||
compiler.typesTask.dynamicType.nonNullable());
|
||||
checkFieldTypeInClass('A', 'fieldParameter', compiler.typesTask.intType);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -95,11 +96,8 @@ main() {
|
||||
main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
|
||||
var compiler = compilerFor(TEST1, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
|
||||
checkReturn(String name, type) {
|
||||
checkReturn(MockCompiler compiler, String name, type) {
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
var element = findElement(compiler, name);
|
||||
Expect.equals(
|
||||
type,
|
||||
@@ -107,27 +105,33 @@ main() {
|
||||
name);
|
||||
}
|
||||
|
||||
checkReturn('test1', compiler.typesTask.intType);
|
||||
checkReturn('test2', compiler.typesTask.dynamicType.nonNullable());
|
||||
checkReturn('test3', compiler.typesTask.intType);
|
||||
checkReturn('test4', compiler.typesTask.mapType);
|
||||
checkReturn('test5', compiler.typesTask.dynamicType.nonNullable());
|
||||
checkReturn('test6', compiler.typesTask.dynamicType.nonNullable());
|
||||
var compiler1 = compilerFor(TEST1, uri);
|
||||
asyncTest(() => compiler1.runCompiler(uri).then((_) {
|
||||
checkReturn(compiler1, 'test1', compiler1.typesTask.intType);
|
||||
checkReturn(compiler1, 'test2',
|
||||
compiler1.typesTask.dynamicType.nonNullable());
|
||||
checkReturn(compiler1, 'test3', compiler1.typesTask.intType);
|
||||
checkReturn(compiler1, 'test4', compiler1.typesTask.mapType);
|
||||
checkReturn(compiler1, 'test5',
|
||||
compiler1.typesTask.dynamicType.nonNullable());
|
||||
checkReturn(compiler1, 'test6',
|
||||
compiler1.typesTask.dynamicType.nonNullable());
|
||||
}));
|
||||
|
||||
compiler = compilerFor(TEST2, uri);
|
||||
compiler.runCompiler(uri);
|
||||
typesInferrer = compiler.typesTask.typesInferrer;
|
||||
var compiler2 = compilerFor(TEST2, uri);
|
||||
asyncTest(() => compiler2.runCompiler(uri).then((_) {
|
||||
checkReturn(compiler2, 'test1',
|
||||
compiler2.typesTask.dynamicType.nonNullable());
|
||||
checkReturn(compiler2, 'test2', compiler2.typesTask.mapType);
|
||||
checkReturn(compiler2, 'test3', compiler2.typesTask.mapType);
|
||||
checkReturn(compiler2, 'test4', compiler2.typesTask.mapType);
|
||||
checkReturn(compiler2, 'test5', compiler2.typesTask.mapType);
|
||||
|
||||
checkReturn('test1', compiler.typesTask.dynamicType.nonNullable());
|
||||
checkReturn('test2', compiler.typesTask.mapType);
|
||||
checkReturn('test3', compiler.typesTask.mapType);
|
||||
checkReturn('test4', compiler.typesTask.mapType);
|
||||
checkReturn('test5', compiler.typesTask.mapType);
|
||||
|
||||
checkReturn('test6', compiler.typesTask.numType);
|
||||
checkReturn('test7', compiler.typesTask.intType);
|
||||
checkReturn('test8', compiler.typesTask.intType);
|
||||
checkReturn('test9', compiler.typesTask.intType);
|
||||
checkReturn('test10', compiler.typesTask.numType);
|
||||
checkReturn('test11', compiler.typesTask.doubleType);
|
||||
checkReturn(compiler2, 'test6', compiler2.typesTask.numType);
|
||||
checkReturn(compiler2, 'test7', compiler2.typesTask.intType);
|
||||
checkReturn(compiler2, 'test8', compiler2.typesTask.intType);
|
||||
checkReturn(compiler2, 'test9', compiler2.typesTask.intType);
|
||||
checkReturn(compiler2, 'test10', compiler2.typesTask.numType);
|
||||
checkReturn(compiler2, 'test11', compiler2.typesTask.doubleType);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -13,7 +14,7 @@ class A {
|
||||
set foo(value) {}
|
||||
operator[](index) => 'string';
|
||||
operator[]=(index, value) {}
|
||||
|
||||
|
||||
returnDynamic1() => foo--;
|
||||
returnNum1() => --foo;
|
||||
returnNum2() => foo -= 42;
|
||||
@@ -63,34 +64,35 @@ main() {
|
||||
void main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesTask = compiler.typesTask;
|
||||
var typesInferrer = typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesTask = compiler.typesTask;
|
||||
var typesInferrer = typesTask.typesInferrer;
|
||||
|
||||
checkReturnInClass(String className, String methodName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(methodName));
|
||||
Expect.equals(type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
checkReturnInClass(String className, String methodName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(methodName));
|
||||
Expect.equals(type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
|
||||
var subclassOfInterceptor =
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
|
||||
var subclassOfInterceptor =
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
|
||||
|
||||
checkReturnInClass('A', 'returnNum1', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnNum2', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnNum3', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnNum4', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnNum5', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnNum6', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnDynamic1', subclassOfInterceptor);
|
||||
checkReturnInClass('A', 'returnDynamic2', subclassOfInterceptor);
|
||||
checkReturnInClass('A', 'returnDynamic3', typesTask.dynamicType);
|
||||
checkReturnInClass('A', 'returnNum1', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnNum2', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnNum3', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnNum4', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnNum5', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnNum6', typesTask.numType);
|
||||
checkReturnInClass('A', 'returnDynamic1', subclassOfInterceptor);
|
||||
checkReturnInClass('A', 'returnDynamic2', subclassOfInterceptor);
|
||||
checkReturnInClass('A', 'returnDynamic3', typesTask.dynamicType);
|
||||
|
||||
checkReturnInClass('B', 'returnString1', typesTask.stringType);
|
||||
checkReturnInClass('B', 'returnString2', typesTask.stringType);
|
||||
checkReturnInClass('B', 'returnDynamic1', typesTask.dynamicType);
|
||||
checkReturnInClass('B', 'returnDynamic2', typesTask.dynamicType);
|
||||
checkReturnInClass('B', 'returnDynamic3', typesTask.dynamicType);
|
||||
checkReturnInClass('B', 'returnDynamic4', typesTask.dynamicType);
|
||||
checkReturnInClass('B', 'returnString1', typesTask.stringType);
|
||||
checkReturnInClass('B', 'returnString2', typesTask.stringType);
|
||||
checkReturnInClass('B', 'returnDynamic1', typesTask.dynamicType);
|
||||
checkReturnInClass('B', 'returnDynamic2', typesTask.dynamicType);
|
||||
checkReturnInClass('B', 'returnDynamic3', typesTask.dynamicType);
|
||||
checkReturnInClass('B', 'returnDynamic4', typesTask.dynamicType);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import
|
||||
'../../../sdk/lib/_internal/compiler/implementation/types/types.dart'
|
||||
show TypeMask;
|
||||
@@ -51,9 +52,10 @@ main() {
|
||||
""";
|
||||
|
||||
void main() {
|
||||
String generated = compileAll(TEST);
|
||||
if (generated.contains(r'=== true')) {
|
||||
print(generated);
|
||||
Expect.fail("missing elision of '=== true'");
|
||||
}
|
||||
asyncTest(() => compileAll(TEST).then((generated) {
|
||||
if (generated.contains(r'=== true')) {
|
||||
print(generated);
|
||||
Expect.fail("missing elision of '=== true'");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import
|
||||
'../../../sdk/lib/_internal/compiler/implementation/types/types.dart'
|
||||
show TypeMask;
|
||||
@@ -597,123 +598,125 @@ main() {
|
||||
void main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesTask = compiler.typesTask;
|
||||
var typesInferrer = typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesTask = compiler.typesTask;
|
||||
var typesInferrer = typesTask.typesInferrer;
|
||||
|
||||
checkReturn(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
Expect.equals(
|
||||
type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler),
|
||||
name);
|
||||
}
|
||||
var interceptorType =
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
|
||||
checkReturn(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
Expect.equals(
|
||||
type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler),
|
||||
name);
|
||||
}
|
||||
var interceptorType =
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
|
||||
|
||||
checkReturn('returnNum1', typesTask.numType);
|
||||
checkReturn('returnNum2', typesTask.numType);
|
||||
checkReturn('returnInt1', typesTask.intType);
|
||||
checkReturn('returnInt2', typesTask.intType);
|
||||
checkReturn('returnDouble', typesTask.doubleType);
|
||||
checkReturn('returnGiveUp', interceptorType);
|
||||
checkReturn('returnInt5', typesTask.intType);
|
||||
checkReturn('returnInt6', typesTask.intType);
|
||||
checkReturn('returnIntOrNull', typesTask.intType.nullable());
|
||||
checkReturn('returnInt3', typesTask.intType);
|
||||
checkReturn('returnDynamic', typesTask.dynamicType);
|
||||
checkReturn('returnInt4', typesTask.intType);
|
||||
checkReturn('returnInt7', typesTask.intType);
|
||||
checkReturn('returnInt8', typesTask.intType);
|
||||
checkReturn('returnDynamic1', typesTask.dynamicType);
|
||||
checkReturn('returnDynamic2', typesTask.dynamicType);
|
||||
TypeMask intType = new TypeMask.nonNullSubtype(compiler.intClass.rawType);
|
||||
checkReturn('testIsCheck1', intType);
|
||||
checkReturn('testIsCheck2', intType);
|
||||
checkReturn('testIsCheck3', intType.nullable());
|
||||
checkReturn('testIsCheck4', intType);
|
||||
checkReturn('testIsCheck5', intType);
|
||||
checkReturn('testIsCheck6', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck7', intType);
|
||||
checkReturn('testIsCheck8', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck9', intType);
|
||||
checkReturn('testIsCheck10', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck11', intType);
|
||||
checkReturn('testIsCheck12', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck13', intType);
|
||||
checkReturn('testIsCheck14', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck15', intType);
|
||||
checkReturn('testIsCheck16', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck17', intType);
|
||||
checkReturn('testIsCheck18', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck19', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck20', typesTask.dynamicType.nonNullable());
|
||||
checkReturn('testIf1', typesTask.intType.nullable());
|
||||
checkReturn('testIf2', typesTask.intType.nullable());
|
||||
checkReturn('returnAsString',
|
||||
new TypeMask.subtype(compiler.stringClass.computeType(compiler)));
|
||||
checkReturn('returnIntAsNum', typesTask.intType);
|
||||
checkReturn('returnAsTypedef', typesTask.functionType.nullable());
|
||||
checkReturn('returnTopLevelGetter', typesTask.intType);
|
||||
checkReturn('testDeadCode', typesTask.intType);
|
||||
checkReturn('testLabeledIf', typesTask.intType.nullable());
|
||||
checkReturn('testSwitch1', typesTask.intType
|
||||
.union(typesTask.doubleType, compiler).nullable().simplify(compiler));
|
||||
checkReturn('testSwitch2', typesTask.intType);
|
||||
checkReturn('testSwitch3', interceptorType.nullable());
|
||||
checkReturn('testSwitch4', typesTask.intType);
|
||||
checkReturn('testSwitch5', typesTask.intType);
|
||||
checkReturn('testContinue1', interceptorType.nullable());
|
||||
checkReturn('testBreak1', interceptorType.nullable());
|
||||
checkReturn('testContinue2', interceptorType.nullable());
|
||||
checkReturn('testBreak2', typesTask.intType.nullable());
|
||||
checkReturn('testReturnElementOfConstList1', typesTask.intType);
|
||||
checkReturn('testReturnElementOfConstList2', typesTask.intType);
|
||||
checkReturn('testReturnItselfOrInt', typesTask.intType);
|
||||
checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType);
|
||||
checkReturn('returnNum1', typesTask.numType);
|
||||
checkReturn('returnNum2', typesTask.numType);
|
||||
checkReturn('returnInt1', typesTask.intType);
|
||||
checkReturn('returnInt2', typesTask.intType);
|
||||
checkReturn('returnDouble', typesTask.doubleType);
|
||||
checkReturn('returnGiveUp', interceptorType);
|
||||
checkReturn('returnInt5', typesTask.intType);
|
||||
checkReturn('returnInt6', typesTask.intType);
|
||||
checkReturn('returnIntOrNull', typesTask.intType.nullable());
|
||||
checkReturn('returnInt3', typesTask.intType);
|
||||
checkReturn('returnDynamic', typesTask.dynamicType);
|
||||
checkReturn('returnInt4', typesTask.intType);
|
||||
checkReturn('returnInt7', typesTask.intType);
|
||||
checkReturn('returnInt8', typesTask.intType);
|
||||
checkReturn('returnDynamic1', typesTask.dynamicType);
|
||||
checkReturn('returnDynamic2', typesTask.dynamicType);
|
||||
TypeMask intType = new TypeMask.nonNullSubtype(compiler.intClass.rawType);
|
||||
checkReturn('testIsCheck1', intType);
|
||||
checkReturn('testIsCheck2', intType);
|
||||
checkReturn('testIsCheck3', intType.nullable());
|
||||
checkReturn('testIsCheck4', intType);
|
||||
checkReturn('testIsCheck5', intType);
|
||||
checkReturn('testIsCheck6', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck7', intType);
|
||||
checkReturn('testIsCheck8', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck9', intType);
|
||||
checkReturn('testIsCheck10', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck11', intType);
|
||||
checkReturn('testIsCheck12', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck13', intType);
|
||||
checkReturn('testIsCheck14', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck15', intType);
|
||||
checkReturn('testIsCheck16', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck17', intType);
|
||||
checkReturn('testIsCheck18', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck19', typesTask.dynamicType);
|
||||
checkReturn('testIsCheck20', typesTask.dynamicType.nonNullable());
|
||||
checkReturn('testIf1', typesTask.intType.nullable());
|
||||
checkReturn('testIf2', typesTask.intType.nullable());
|
||||
checkReturn('returnAsString',
|
||||
new TypeMask.subtype(compiler.stringClass.computeType(compiler)));
|
||||
checkReturn('returnIntAsNum', typesTask.intType);
|
||||
checkReturn('returnAsTypedef', typesTask.functionType.nullable());
|
||||
checkReturn('returnTopLevelGetter', typesTask.intType);
|
||||
checkReturn('testDeadCode', typesTask.intType);
|
||||
checkReturn('testLabeledIf', typesTask.intType.nullable());
|
||||
checkReturn('testSwitch1', typesTask.intType
|
||||
.union(typesTask.doubleType, compiler)
|
||||
.nullable().simplify(compiler));
|
||||
checkReturn('testSwitch2', typesTask.intType);
|
||||
checkReturn('testSwitch3', interceptorType.nullable());
|
||||
checkReturn('testSwitch4', typesTask.intType);
|
||||
checkReturn('testSwitch5', typesTask.intType);
|
||||
checkReturn('testContinue1', interceptorType.nullable());
|
||||
checkReturn('testBreak1', interceptorType.nullable());
|
||||
checkReturn('testContinue2', interceptorType.nullable());
|
||||
checkReturn('testBreak2', typesTask.intType.nullable());
|
||||
checkReturn('testReturnElementOfConstList1', typesTask.intType);
|
||||
checkReturn('testReturnElementOfConstList2', typesTask.intType);
|
||||
checkReturn('testReturnItselfOrInt', typesTask.intType);
|
||||
checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType);
|
||||
|
||||
checkReturn('testDoWhile1', typesTask.stringType);
|
||||
checkReturn('testDoWhile2', typesTask.nullType);
|
||||
checkReturn('testDoWhile3', interceptorType);
|
||||
checkReturn('testDoWhile4', typesTask.numType);
|
||||
checkReturn('testDoWhile1', typesTask.stringType);
|
||||
checkReturn('testDoWhile2', typesTask.nullType);
|
||||
checkReturn('testDoWhile3', interceptorType);
|
||||
checkReturn('testDoWhile4', typesTask.numType);
|
||||
|
||||
checkReturnInClass(String className, String methodName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(methodName));
|
||||
Expect.equals(type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
checkReturnInClass(String className, String methodName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(methodName));
|
||||
Expect.equals(type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
|
||||
checkReturnInClass('A', 'returnInt1', typesTask.intType);
|
||||
checkReturnInClass('A', 'returnInt2', typesTask.intType);
|
||||
checkReturnInClass('A', 'returnInt3', typesTask.intType);
|
||||
checkReturnInClass('A', 'returnInt4', typesTask.intType);
|
||||
checkReturnInClass('A', 'returnInt5', typesTask.intType);
|
||||
checkReturnInClass('A', 'returnInt6', typesTask.intType);
|
||||
checkReturnInClass('A', '==', interceptorType);
|
||||
checkReturnInClass('A', 'returnInt1', typesTask.intType);
|
||||
checkReturnInClass('A', 'returnInt2', typesTask.intType);
|
||||
checkReturnInClass('A', 'returnInt3', typesTask.intType);
|
||||
checkReturnInClass('A', 'returnInt4', typesTask.intType);
|
||||
checkReturnInClass('A', 'returnInt5', typesTask.intType);
|
||||
checkReturnInClass('A', 'returnInt6', typesTask.intType);
|
||||
checkReturnInClass('A', '==', interceptorType);
|
||||
|
||||
checkReturnInClass('B', 'returnInt1', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt2', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt3', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt4', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt5', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt6', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt7', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt8', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt9', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt1', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt2', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt3', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt4', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt5', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt6', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt7', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt8', typesTask.intType);
|
||||
checkReturnInClass('B', 'returnInt9', typesTask.intType);
|
||||
|
||||
checkFactoryConstructor(String className, String factoryName) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.localLookup(buildSourceString(factoryName));
|
||||
Expect.equals(new TypeMask.nonNullExact(cls.rawType),
|
||||
typesInferrer.getReturnTypeOfElement(element));
|
||||
}
|
||||
checkFactoryConstructor('A', '');
|
||||
checkFactoryConstructor(String className, String factoryName) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.localLookup(buildSourceString(factoryName));
|
||||
Expect.equals(new TypeMask.nonNullExact(cls.rawType),
|
||||
typesInferrer.getReturnTypeOfElement(element));
|
||||
}
|
||||
checkFactoryConstructor('A', '');
|
||||
|
||||
checkReturn('testCascade1', typesTask.growableListType);
|
||||
checkReturn('testCascade2', new TypeMask.nonNullExact(
|
||||
typesTask.rawTypeOf(findElement(compiler, 'CascadeHelper'))));
|
||||
checkReturn('testSpecialization1', typesTask.numType);
|
||||
checkReturn('testSpecialization2', typesTask.dynamicType);
|
||||
checkReturn('testSpecialization3', typesTask.intType.nullable());
|
||||
checkReturn('testCascade1', typesTask.growableListType);
|
||||
checkReturn('testCascade2', new TypeMask.nonNullExact(
|
||||
typesTask.rawTypeOf(findElement(compiler, 'CascadeHelper'))));
|
||||
checkReturn('testSpecialization1', typesTask.numType);
|
||||
checkReturn('testSpecialization2', typesTask.dynamicType);
|
||||
checkReturn('testSpecialization3', typesTask.intType.nullable());
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/types/types.dart'
|
||||
show TypeMask;
|
||||
|
||||
@@ -166,32 +167,32 @@ main() {
|
||||
void main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesTask = compiler.typesTask;
|
||||
var typesInferrer = typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesTask = compiler.typesTask;
|
||||
var typesInferrer = typesTask.typesInferrer;
|
||||
|
||||
checkReturn(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
Expect.equals(type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
checkReturn(String name, type) {
|
||||
var element = findElement(compiler, name);
|
||||
Expect.equals(type,
|
||||
typesInferrer.getReturnTypeOfElement(element).simplify(compiler));
|
||||
}
|
||||
|
||||
checkReturn('returnInt1', typesTask.intType);
|
||||
checkReturn('returnInt2', typesTask.intType);
|
||||
checkReturn('returnInt3', typesTask.intType);
|
||||
checkReturn('returnInt4', typesTask.intType);
|
||||
checkReturn('returnInt5', typesTask.intType);
|
||||
checkReturn('returnInt6',
|
||||
new TypeMask.nonNullSubtype(compiler.intClass.rawType));
|
||||
checkReturn('returnInt7', typesTask.intType);
|
||||
checkReturn('returnInt1', typesTask.intType);
|
||||
checkReturn('returnInt2', typesTask.intType);
|
||||
checkReturn('returnInt3', typesTask.intType);
|
||||
checkReturn('returnInt4', typesTask.intType);
|
||||
checkReturn('returnInt5', typesTask.intType);
|
||||
checkReturn('returnInt6',
|
||||
new TypeMask.nonNullSubtype(compiler.intClass.rawType));
|
||||
|
||||
var subclassOfInterceptor =
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
|
||||
var subclassOfInterceptor =
|
||||
findTypeMask(compiler, 'Interceptor', 'nonNullSubclass');
|
||||
|
||||
checkReturn('returnDyn1', subclassOfInterceptor);
|
||||
checkReturn('returnDyn2', subclassOfInterceptor);
|
||||
checkReturn('returnDyn3', subclassOfInterceptor);
|
||||
checkReturn('returnDyn4', subclassOfInterceptor);
|
||||
checkReturn('returnDyn5', subclassOfInterceptor);
|
||||
checkReturn('returnDyn6', typesTask.dynamicType);
|
||||
checkReturn('returnDyn1', subclassOfInterceptor);
|
||||
checkReturn('returnDyn2', subclassOfInterceptor);
|
||||
checkReturn('returnDyn3', subclassOfInterceptor);
|
||||
checkReturn('returnDyn4', subclassOfInterceptor);
|
||||
checkReturn('returnDyn5', subclassOfInterceptor);
|
||||
checkReturn('returnDyn6', typesTask.dynamicType);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
import 'parser_helper.dart';
|
||||
|
||||
@@ -32,14 +32,15 @@ main() {
|
||||
void main() {
|
||||
Uri uri = new Uri(scheme: 'source');
|
||||
var compiler = compilerFor(TEST, uri);
|
||||
compiler.runCompiler(uri);
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
var typesInferrer = compiler.typesTask.typesInferrer;
|
||||
|
||||
checkReturnInClass(String className, String methodName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(methodName));
|
||||
Expect.equals(type, typesInferrer.getReturnTypeOfElement(element));
|
||||
}
|
||||
checkReturnInClass(String className, String methodName, type) {
|
||||
var cls = findElement(compiler, className);
|
||||
var element = cls.lookupLocalMember(buildSourceString(methodName));
|
||||
Expect.equals(type, typesInferrer.getReturnTypeOfElement(element));
|
||||
}
|
||||
|
||||
checkReturnInClass('A', '+', compiler.typesTask.intType);
|
||||
checkReturnInClass('A', '+', compiler.typesTask.intType);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "compiler_helper.dart";
|
||||
|
||||
const String TEST = "main() => [];";
|
||||
@@ -25,10 +26,12 @@ const String DEFAULT_CORELIB_WITH_LIST = r'''
|
||||
''';
|
||||
|
||||
main() {
|
||||
String generated = compileAll(TEST, coreSource: DEFAULT_CORELIB_WITH_LIST);
|
||||
MockCompiler compiler = new MockCompiler();
|
||||
var backend = compiler.backend;
|
||||
asyncTest(() => compileAll(TEST, coreSource: DEFAULT_CORELIB_WITH_LIST).
|
||||
then((generated) {
|
||||
MockCompiler compiler = new MockCompiler();
|
||||
var backend = compiler.backend;
|
||||
|
||||
// Make sure no class is emitted.
|
||||
Expect.isFalse(generated.contains(backend.emitter.finishClassesName));
|
||||
// Make sure no class is emitted.
|
||||
Expect.isFalse(generated.contains(backend.emitter.finishClassesName));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -2,19 +2,21 @@
|
||||
// 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.
|
||||
|
||||
import 'dart:async';
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart";
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart';
|
||||
import "mock_compiler.dart";
|
||||
import 'parser_helper.dart';
|
||||
|
||||
CodeBuffer compileAll(SourceFile sourceFile) {
|
||||
Future<CodeBuffer> compileAll(SourceFile sourceFile) {
|
||||
MockCompiler compiler = new MockCompiler();
|
||||
Uri uri = new Uri(path: sourceFile.filename);
|
||||
compiler.sourceFiles[uri.toString()] = sourceFile;
|
||||
compiler.runCompiler(uri);
|
||||
return compiler.backend.emitter.mainBuffer;
|
||||
return compiler.runCompiler(uri).then((_) {
|
||||
return compiler.backend.emitter.mainBuffer;
|
||||
});
|
||||
}
|
||||
|
||||
void testSourceMapLocations(String codeWithMarkers) {
|
||||
@@ -27,27 +29,27 @@ void testSourceMapLocations(String codeWithMarkers) {
|
||||
String code = codeWithMarkers.replaceAll('@', '');
|
||||
|
||||
SourceFile sourceFile = new SourceFile('<test script>', code);
|
||||
CodeBuffer buffer = compileAll(sourceFile);
|
||||
asyncTest(() => compileAll(sourceFile).then((CodeBuffer buffer) {
|
||||
Set<int> locations = new Set<int>();
|
||||
buffer.forEachSourceLocation((int offset, var sourcePosition) {
|
||||
if (sourcePosition != null && sourcePosition.sourceFile == sourceFile) {
|
||||
locations.add(sourcePosition.token.charOffset);
|
||||
}
|
||||
});
|
||||
|
||||
Set<int> locations = new Set<int>();
|
||||
buffer.forEachSourceLocation((int offset, var sourcePosition) {
|
||||
if (sourcePosition != null && sourcePosition.sourceFile == sourceFile) {
|
||||
locations.add(sourcePosition.token.charOffset);
|
||||
for (int i = 0; i < expectedLocations.length; ++i) {
|
||||
int expectedLocation = expectedLocations[i];
|
||||
if (!locations.contains(expectedLocation)) {
|
||||
int originalLocation = expectedLocation + i;
|
||||
SourceFile sourceFileWithMarkers = new SourceFile('<test script>',
|
||||
codeWithMarkers);
|
||||
String message = sourceFileWithMarkers.getLocationMessage(
|
||||
'Missing location', originalLocation, originalLocation + 1, true,
|
||||
(s) => s);
|
||||
Expect.fail(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < expectedLocations.length; ++i) {
|
||||
int expectedLocation = expectedLocations[i];
|
||||
if (!locations.contains(expectedLocation)) {
|
||||
int originalLocation = expectedLocation + i;
|
||||
SourceFile sourceFileWithMarkers = new SourceFile('<test script>',
|
||||
codeWithMarkers);
|
||||
String message = sourceFileWithMarkers.getLocationMessage(
|
||||
'Missing location', originalLocation, originalLocation + 1, true,
|
||||
(s) => s);
|
||||
Expect.fail(message);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
String FUNCTIONS_TEST = '''
|
||||
|
||||
@@ -5,17 +5,19 @@
|
||||
// Test that static functions are closurized as expected.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
main() {
|
||||
String code = compileAll(r'''main() { print(main); }''');
|
||||
asyncTest(() => compileAll(r'''main() { print(main); }''').then((code) {
|
||||
// At some point, we will have to closurize global functions
|
||||
// differently, at which point this test will break. Then it is time
|
||||
// to implement a way to call a Dart closure from JS foreign
|
||||
// functions.
|
||||
|
||||
// At some point, we will have to closurize global functions
|
||||
// differently, at which point this test will break. Then it is time
|
||||
// to implement a way to call a Dart closure from JS foreign
|
||||
// functions.
|
||||
|
||||
// If this test fail, please take a look at the use of
|
||||
// toStringWrapper in captureStackTrace in js_helper.dart.
|
||||
Expect.isTrue(code.contains(new RegExp(r'print\([$a-z]+\.main\$closure\);')));
|
||||
// If this test fail, please take a look at the use of
|
||||
// toStringWrapper in captureStackTrace in js_helper.dart.
|
||||
Expect.isTrue(code.contains(
|
||||
new RegExp(r'print\([$a-z]+\.main\$closure\);')));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,13 +3,17 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
main() {
|
||||
String code =
|
||||
compileAll(r'''main() { return "${2}${true}${'a'}${3.14}"; }''');
|
||||
Expect.isTrue(code.contains(r'2truea3.14'));
|
||||
asyncTest(() => compileAll(
|
||||
r'''main() { return "${2}${true}${'a'}${3.14}"; }''').then((code) {
|
||||
Expect.isTrue(code.contains(r'2truea3.14'));
|
||||
}));
|
||||
|
||||
code = compileAll(r'''main() { return "foo ${new Object()}"; }''');
|
||||
Expect.isFalse(code.contains(r'concat'));
|
||||
asyncTest(() => compileAll(
|
||||
r'''main() { return "foo ${new Object()}"; }''').then((code) {
|
||||
Expect.isFalse(code.contains(r'concat'));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
library subtype_test;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'type_test_helper.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart';
|
||||
import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart"
|
||||
@@ -23,210 +24,210 @@ void main() {
|
||||
}
|
||||
|
||||
void testInterfaceSubtype() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
class A<T> {}
|
||||
class B<T1, T2> extends A<T1> {}
|
||||
// TODO(johnniwinther): Inheritance with different type arguments is
|
||||
// currently not supported by the implementation.
|
||||
class C<T1, T2> extends B<T2, T1> /*implements A<A<T1>>*/ {}
|
||||
""");
|
||||
""").then((env) {
|
||||
|
||||
void expect(bool value, DartType T, DartType S) {
|
||||
Expect.equals(value, env.isSubtype(T, S), '$T <: $S');
|
||||
}
|
||||
void expect(bool value, DartType T, DartType S) {
|
||||
Expect.equals(value, env.isSubtype(T, S), '$T <: $S');
|
||||
}
|
||||
|
||||
ClassElement A = env.getElement('A');
|
||||
ClassElement B = env.getElement('B');
|
||||
ClassElement C = env.getElement('C');
|
||||
DartType Object_ = env['Object'];
|
||||
DartType num_ = env['num'];
|
||||
DartType int_ = env['int'];
|
||||
DartType String_ = env['String'];
|
||||
DartType dynamic_ = env['dynamic'];
|
||||
ClassElement A = env.getElement('A');
|
||||
ClassElement B = env.getElement('B');
|
||||
ClassElement C = env.getElement('C');
|
||||
DartType Object_ = env['Object'];
|
||||
DartType num_ = env['num'];
|
||||
DartType int_ = env['int'];
|
||||
DartType String_ = env['String'];
|
||||
DartType dynamic_ = env['dynamic'];
|
||||
|
||||
expect(true, Object_, Object_);
|
||||
expect(true, num_, Object_);
|
||||
expect(true, int_, Object_);
|
||||
expect(true, String_, Object_);
|
||||
expect(true, dynamic_, Object_);
|
||||
expect(true, Object_, Object_);
|
||||
expect(true, num_, Object_);
|
||||
expect(true, int_, Object_);
|
||||
expect(true, String_, Object_);
|
||||
expect(true, dynamic_, Object_);
|
||||
|
||||
expect(false, Object_, num_);
|
||||
expect(true, num_, num_);
|
||||
expect(true, int_, num_);
|
||||
expect(false, String_, num_);
|
||||
expect(true, dynamic_, num_);
|
||||
expect(false, Object_, num_);
|
||||
expect(true, num_, num_);
|
||||
expect(true, int_, num_);
|
||||
expect(false, String_, num_);
|
||||
expect(true, dynamic_, num_);
|
||||
|
||||
expect(false, Object_, int_);
|
||||
expect(false, num_, int_);
|
||||
expect(true, int_, int_);
|
||||
expect(false, String_, int_);
|
||||
expect(true, dynamic_, int_);
|
||||
expect(false, Object_, int_);
|
||||
expect(false, num_, int_);
|
||||
expect(true, int_, int_);
|
||||
expect(false, String_, int_);
|
||||
expect(true, dynamic_, int_);
|
||||
|
||||
expect(false, Object_, String_);
|
||||
expect(false, num_, String_);
|
||||
expect(false, int_, String_);
|
||||
expect(true, String_, String_);
|
||||
expect(true, dynamic_, String_);
|
||||
expect(false, Object_, String_);
|
||||
expect(false, num_, String_);
|
||||
expect(false, int_, String_);
|
||||
expect(true, String_, String_);
|
||||
expect(true, dynamic_, String_);
|
||||
|
||||
expect(true, Object_, dynamic_);
|
||||
expect(true, num_, dynamic_);
|
||||
expect(true, int_, dynamic_);
|
||||
expect(true, String_, dynamic_);
|
||||
expect(true, dynamic_, dynamic_);
|
||||
expect(true, Object_, dynamic_);
|
||||
expect(true, num_, dynamic_);
|
||||
expect(true, int_, dynamic_);
|
||||
expect(true, String_, dynamic_);
|
||||
expect(true, dynamic_, dynamic_);
|
||||
|
||||
DartType A_Object = instantiate(A, [Object_]);
|
||||
DartType A_num = instantiate(A, [num_]);
|
||||
DartType A_int = instantiate(A, [int_]);
|
||||
DartType A_String = instantiate(A, [String_]);
|
||||
DartType A_dynamic = instantiate(A, [dynamic_]);
|
||||
DartType A_Object = instantiate(A, [Object_]);
|
||||
DartType A_num = instantiate(A, [num_]);
|
||||
DartType A_int = instantiate(A, [int_]);
|
||||
DartType A_String = instantiate(A, [String_]);
|
||||
DartType A_dynamic = instantiate(A, [dynamic_]);
|
||||
|
||||
expect(true, A_Object, Object_);
|
||||
expect(false, A_Object, num_);
|
||||
expect(false, A_Object, int_);
|
||||
expect(false, A_Object, String_);
|
||||
expect(true, A_Object, dynamic_);
|
||||
expect(true, A_Object, Object_);
|
||||
expect(false, A_Object, num_);
|
||||
expect(false, A_Object, int_);
|
||||
expect(false, A_Object, String_);
|
||||
expect(true, A_Object, dynamic_);
|
||||
|
||||
expect(true, A_Object, A_Object);
|
||||
expect(true, A_num, A_Object);
|
||||
expect(true, A_int, A_Object);
|
||||
expect(true, A_String, A_Object);
|
||||
expect(true, A_dynamic, A_Object);
|
||||
expect(true, A_Object, A_Object);
|
||||
expect(true, A_num, A_Object);
|
||||
expect(true, A_int, A_Object);
|
||||
expect(true, A_String, A_Object);
|
||||
expect(true, A_dynamic, A_Object);
|
||||
|
||||
expect(false, A_Object, A_num);
|
||||
expect(true, A_num, A_num);
|
||||
expect(true, A_int, A_num);
|
||||
expect(false, A_String, A_num);
|
||||
expect(true, A_dynamic, A_num);
|
||||
expect(false, A_Object, A_num);
|
||||
expect(true, A_num, A_num);
|
||||
expect(true, A_int, A_num);
|
||||
expect(false, A_String, A_num);
|
||||
expect(true, A_dynamic, A_num);
|
||||
|
||||
expect(false, A_Object, A_int);
|
||||
expect(false, A_num, A_int);
|
||||
expect(true, A_int, A_int);
|
||||
expect(false, A_String, A_int);
|
||||
expect(true, A_dynamic, A_int);
|
||||
expect(false, A_Object, A_int);
|
||||
expect(false, A_num, A_int);
|
||||
expect(true, A_int, A_int);
|
||||
expect(false, A_String, A_int);
|
||||
expect(true, A_dynamic, A_int);
|
||||
|
||||
expect(false, A_Object, A_String);
|
||||
expect(false, A_num, A_String);
|
||||
expect(false, A_int, A_String);
|
||||
expect(true, A_String, A_String);
|
||||
expect(true, A_dynamic, A_String);
|
||||
expect(false, A_Object, A_String);
|
||||
expect(false, A_num, A_String);
|
||||
expect(false, A_int, A_String);
|
||||
expect(true, A_String, A_String);
|
||||
expect(true, A_dynamic, A_String);
|
||||
|
||||
expect(true, A_Object, A_dynamic);
|
||||
expect(true, A_num, A_dynamic);
|
||||
expect(true, A_int, A_dynamic);
|
||||
expect(true, A_String, A_dynamic);
|
||||
expect(true, A_dynamic, A_dynamic);
|
||||
expect(true, A_Object, A_dynamic);
|
||||
expect(true, A_num, A_dynamic);
|
||||
expect(true, A_int, A_dynamic);
|
||||
expect(true, A_String, A_dynamic);
|
||||
expect(true, A_dynamic, A_dynamic);
|
||||
|
||||
DartType B_Object_Object = instantiate(B, [Object_, Object_]);
|
||||
DartType B_num_num = instantiate(B, [num_, num_]);
|
||||
DartType B_int_num = instantiate(B, [int_, num_]);
|
||||
DartType B_dynamic_dynamic = instantiate(B, [dynamic_, dynamic_]);
|
||||
DartType B_String_dynamic = instantiate(B, [String_, dynamic_]);
|
||||
DartType B_Object_Object = instantiate(B, [Object_, Object_]);
|
||||
DartType B_num_num = instantiate(B, [num_, num_]);
|
||||
DartType B_int_num = instantiate(B, [int_, num_]);
|
||||
DartType B_dynamic_dynamic = instantiate(B, [dynamic_, dynamic_]);
|
||||
DartType B_String_dynamic = instantiate(B, [String_, dynamic_]);
|
||||
|
||||
expect(true, B_Object_Object, Object_);
|
||||
expect(true, B_Object_Object, A_Object);
|
||||
expect(false, B_Object_Object, A_num);
|
||||
expect(false, B_Object_Object, A_int);
|
||||
expect(false, B_Object_Object, A_String);
|
||||
expect(true, B_Object_Object, A_dynamic);
|
||||
expect(true, B_Object_Object, Object_);
|
||||
expect(true, B_Object_Object, A_Object);
|
||||
expect(false, B_Object_Object, A_num);
|
||||
expect(false, B_Object_Object, A_int);
|
||||
expect(false, B_Object_Object, A_String);
|
||||
expect(true, B_Object_Object, A_dynamic);
|
||||
|
||||
expect(true, B_num_num, Object_);
|
||||
expect(true, B_num_num, A_Object);
|
||||
expect(true, B_num_num, A_num);
|
||||
expect(false, B_num_num, A_int);
|
||||
expect(false, B_num_num, A_String);
|
||||
expect(true, B_num_num, A_dynamic);
|
||||
expect(true, B_num_num, Object_);
|
||||
expect(true, B_num_num, A_Object);
|
||||
expect(true, B_num_num, A_num);
|
||||
expect(false, B_num_num, A_int);
|
||||
expect(false, B_num_num, A_String);
|
||||
expect(true, B_num_num, A_dynamic);
|
||||
|
||||
expect(true, B_int_num, Object_);
|
||||
expect(true, B_int_num, A_Object);
|
||||
expect(true, B_int_num, A_num);
|
||||
expect(true, B_int_num, A_int);
|
||||
expect(false, B_int_num, A_String);
|
||||
expect(true, B_int_num, A_dynamic);
|
||||
expect(true, B_int_num, Object_);
|
||||
expect(true, B_int_num, A_Object);
|
||||
expect(true, B_int_num, A_num);
|
||||
expect(true, B_int_num, A_int);
|
||||
expect(false, B_int_num, A_String);
|
||||
expect(true, B_int_num, A_dynamic);
|
||||
|
||||
expect(true, B_dynamic_dynamic, Object_);
|
||||
expect(true, B_dynamic_dynamic, A_Object);
|
||||
expect(true, B_dynamic_dynamic, A_num);
|
||||
expect(true, B_dynamic_dynamic, A_int);
|
||||
expect(true, B_dynamic_dynamic, A_String);
|
||||
expect(true, B_dynamic_dynamic, A_dynamic);
|
||||
expect(true, B_dynamic_dynamic, Object_);
|
||||
expect(true, B_dynamic_dynamic, A_Object);
|
||||
expect(true, B_dynamic_dynamic, A_num);
|
||||
expect(true, B_dynamic_dynamic, A_int);
|
||||
expect(true, B_dynamic_dynamic, A_String);
|
||||
expect(true, B_dynamic_dynamic, A_dynamic);
|
||||
|
||||
expect(true, B_String_dynamic, Object_);
|
||||
expect(true, B_String_dynamic, A_Object);
|
||||
expect(false, B_String_dynamic, A_num);
|
||||
expect(false, B_String_dynamic, A_int);
|
||||
expect(true, B_String_dynamic, A_String);
|
||||
expect(true, B_String_dynamic, A_dynamic);
|
||||
expect(true, B_String_dynamic, Object_);
|
||||
expect(true, B_String_dynamic, A_Object);
|
||||
expect(false, B_String_dynamic, A_num);
|
||||
expect(false, B_String_dynamic, A_int);
|
||||
expect(true, B_String_dynamic, A_String);
|
||||
expect(true, B_String_dynamic, A_dynamic);
|
||||
|
||||
expect(true, B_Object_Object, B_Object_Object);
|
||||
expect(true, B_num_num, B_Object_Object);
|
||||
expect(true, B_int_num, B_Object_Object);
|
||||
expect(true, B_dynamic_dynamic, B_Object_Object);
|
||||
expect(true, B_String_dynamic, B_Object_Object);
|
||||
expect(true, B_Object_Object, B_Object_Object);
|
||||
expect(true, B_num_num, B_Object_Object);
|
||||
expect(true, B_int_num, B_Object_Object);
|
||||
expect(true, B_dynamic_dynamic, B_Object_Object);
|
||||
expect(true, B_String_dynamic, B_Object_Object);
|
||||
|
||||
expect(false, B_Object_Object, B_num_num);
|
||||
expect(true, B_num_num, B_num_num);
|
||||
expect(true, B_int_num, B_num_num);
|
||||
expect(true, B_dynamic_dynamic, B_num_num);
|
||||
expect(false, B_String_dynamic, B_num_num);
|
||||
expect(false, B_Object_Object, B_num_num);
|
||||
expect(true, B_num_num, B_num_num);
|
||||
expect(true, B_int_num, B_num_num);
|
||||
expect(true, B_dynamic_dynamic, B_num_num);
|
||||
expect(false, B_String_dynamic, B_num_num);
|
||||
|
||||
expect(false, B_Object_Object, B_int_num);
|
||||
expect(false, B_num_num, B_int_num);
|
||||
expect(true, B_int_num, B_int_num);
|
||||
expect(true, B_dynamic_dynamic, B_int_num);
|
||||
expect(false, B_String_dynamic, B_int_num);
|
||||
expect(false, B_Object_Object, B_int_num);
|
||||
expect(false, B_num_num, B_int_num);
|
||||
expect(true, B_int_num, B_int_num);
|
||||
expect(true, B_dynamic_dynamic, B_int_num);
|
||||
expect(false, B_String_dynamic, B_int_num);
|
||||
|
||||
expect(true, B_Object_Object, B_dynamic_dynamic);
|
||||
expect(true, B_num_num, B_dynamic_dynamic);
|
||||
expect(true, B_int_num, B_dynamic_dynamic);
|
||||
expect(true, B_dynamic_dynamic, B_dynamic_dynamic);
|
||||
expect(true, B_String_dynamic, B_dynamic_dynamic);
|
||||
expect(true, B_Object_Object, B_dynamic_dynamic);
|
||||
expect(true, B_num_num, B_dynamic_dynamic);
|
||||
expect(true, B_int_num, B_dynamic_dynamic);
|
||||
expect(true, B_dynamic_dynamic, B_dynamic_dynamic);
|
||||
expect(true, B_String_dynamic, B_dynamic_dynamic);
|
||||
|
||||
expect(false, B_Object_Object, B_String_dynamic);
|
||||
expect(false, B_num_num, B_String_dynamic);
|
||||
expect(false, B_int_num, B_String_dynamic);
|
||||
expect(true, B_dynamic_dynamic, B_String_dynamic);
|
||||
expect(true, B_String_dynamic, B_String_dynamic);
|
||||
expect(false, B_Object_Object, B_String_dynamic);
|
||||
expect(false, B_num_num, B_String_dynamic);
|
||||
expect(false, B_int_num, B_String_dynamic);
|
||||
expect(true, B_dynamic_dynamic, B_String_dynamic);
|
||||
expect(true, B_String_dynamic, B_String_dynamic);
|
||||
|
||||
DartType C_Object_Object = instantiate(C, [Object_, Object_]);
|
||||
DartType C_num_num = instantiate(C, [num_, num_]);
|
||||
DartType C_int_String = instantiate(C, [int_, String_]);
|
||||
DartType C_dynamic_dynamic = instantiate(C, [dynamic_, dynamic_]);
|
||||
DartType C_Object_Object = instantiate(C, [Object_, Object_]);
|
||||
DartType C_num_num = instantiate(C, [num_, num_]);
|
||||
DartType C_int_String = instantiate(C, [int_, String_]);
|
||||
DartType C_dynamic_dynamic = instantiate(C, [dynamic_, dynamic_]);
|
||||
|
||||
expect(true, C_Object_Object, B_Object_Object);
|
||||
expect(false, C_Object_Object, B_num_num);
|
||||
expect(false, C_Object_Object, B_int_num);
|
||||
expect(true, C_Object_Object, B_dynamic_dynamic);
|
||||
expect(false, C_Object_Object, B_String_dynamic);
|
||||
expect(true, C_Object_Object, B_Object_Object);
|
||||
expect(false, C_Object_Object, B_num_num);
|
||||
expect(false, C_Object_Object, B_int_num);
|
||||
expect(true, C_Object_Object, B_dynamic_dynamic);
|
||||
expect(false, C_Object_Object, B_String_dynamic);
|
||||
|
||||
expect(true, C_num_num, B_Object_Object);
|
||||
expect(true, C_num_num, B_num_num);
|
||||
expect(false, C_num_num, B_int_num);
|
||||
expect(true, C_num_num, B_dynamic_dynamic);
|
||||
expect(false, C_num_num, B_String_dynamic);
|
||||
expect(true, C_num_num, B_Object_Object);
|
||||
expect(true, C_num_num, B_num_num);
|
||||
expect(false, C_num_num, B_int_num);
|
||||
expect(true, C_num_num, B_dynamic_dynamic);
|
||||
expect(false, C_num_num, B_String_dynamic);
|
||||
|
||||
expect(true, C_int_String, B_Object_Object);
|
||||
expect(false, C_int_String, B_num_num);
|
||||
expect(false, C_int_String, B_int_num);
|
||||
expect(true, C_int_String, B_dynamic_dynamic);
|
||||
expect(true, C_int_String, B_String_dynamic);
|
||||
expect(true, C_int_String, B_Object_Object);
|
||||
expect(false, C_int_String, B_num_num);
|
||||
expect(false, C_int_String, B_int_num);
|
||||
expect(true, C_int_String, B_dynamic_dynamic);
|
||||
expect(true, C_int_String, B_String_dynamic);
|
||||
|
||||
expect(true, C_dynamic_dynamic, B_Object_Object);
|
||||
expect(true, C_dynamic_dynamic, B_num_num);
|
||||
expect(true, C_dynamic_dynamic, B_int_num);
|
||||
expect(true, C_dynamic_dynamic, B_dynamic_dynamic);
|
||||
expect(true, C_dynamic_dynamic, B_String_dynamic);
|
||||
expect(true, C_dynamic_dynamic, B_Object_Object);
|
||||
expect(true, C_dynamic_dynamic, B_num_num);
|
||||
expect(true, C_dynamic_dynamic, B_int_num);
|
||||
expect(true, C_dynamic_dynamic, B_dynamic_dynamic);
|
||||
expect(true, C_dynamic_dynamic, B_String_dynamic);
|
||||
|
||||
expect(false, C_int_String, A_int);
|
||||
expect(true, C_int_String, A_String);
|
||||
// TODO(johnniwinther): Inheritance with different type arguments is
|
||||
// currently not supported by the implementation.
|
||||
//expect(true, C_int_String, instantiate(A, [A_int]));
|
||||
expect(false, C_int_String, instantiate(A, [A_String]));
|
||||
expect(false, C_int_String, A_int);
|
||||
expect(true, C_int_String, A_String);
|
||||
// TODO(johnniwinther): Inheritance with different type arguments is
|
||||
// currently not supported by the implementation.
|
||||
//expect(true, C_int_String, instantiate(A, [A_int]));
|
||||
expect(false, C_int_String, instantiate(A, [A_String]));
|
||||
}));
|
||||
}
|
||||
|
||||
void testCallableSubtype() {
|
||||
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
class U {}
|
||||
class V extends U {}
|
||||
class W extends V {}
|
||||
@@ -239,31 +240,31 @@ void testCallableSubtype() {
|
||||
int m4(V v, U u);
|
||||
void m5(V v, int i);
|
||||
}
|
||||
""");
|
||||
""").then((env) {
|
||||
void expect(bool value, DartType T, DartType S) {
|
||||
Expect.equals(value, env.isSubtype(T, S), '$T <: $S');
|
||||
}
|
||||
|
||||
void expect(bool value, DartType T, DartType S) {
|
||||
Expect.equals(value, env.isSubtype(T, S), '$T <: $S');
|
||||
}
|
||||
ClassElement classA = env.getElement('A');
|
||||
DartType A = classA.rawType;
|
||||
DartType function = env['Function'];
|
||||
DartType m1 = env.getMemberType(classA, 'm1');
|
||||
DartType m2 = env.getMemberType(classA, 'm2');
|
||||
DartType m3 = env.getMemberType(classA, 'm3');
|
||||
DartType m4 = env.getMemberType(classA, 'm4');
|
||||
DartType m5 = env.getMemberType(classA, 'm5');
|
||||
|
||||
ClassElement classA = env.getElement('A');
|
||||
DartType A = classA.rawType;
|
||||
DartType function = env['Function'];
|
||||
DartType m1 = env.getMemberType(classA, 'm1');
|
||||
DartType m2 = env.getMemberType(classA, 'm2');
|
||||
DartType m3 = env.getMemberType(classA, 'm3');
|
||||
DartType m4 = env.getMemberType(classA, 'm4');
|
||||
DartType m5 = env.getMemberType(classA, 'm5');
|
||||
|
||||
expect(true, A, function);
|
||||
expect(true, A, m1);
|
||||
expect(true, A, m2);
|
||||
expect(false, A, m3);
|
||||
expect(false, A, m4);
|
||||
expect(true, A, m5);
|
||||
expect(true, A, function);
|
||||
expect(true, A, m1);
|
||||
expect(true, A, m2);
|
||||
expect(false, A, m3);
|
||||
expect(false, A, m4);
|
||||
expect(true, A, m5);
|
||||
}));
|
||||
}
|
||||
|
||||
testFunctionSubtyping() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
_() => null;
|
||||
void void_() {}
|
||||
void void_2() {}
|
||||
@@ -280,12 +281,11 @@ testFunctionSubtyping() {
|
||||
int int__int_int(int i1, int i2) => 0;
|
||||
void inline_void_(void f()) {}
|
||||
void inline_void__int(void f(int i)) {}
|
||||
""");
|
||||
functionSubtypingHelper(env);
|
||||
""").then(functionSubtypingHelper));
|
||||
}
|
||||
|
||||
testTypedefSubtyping() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
typedef _();
|
||||
typedef void void_();
|
||||
typedef void void_2();
|
||||
@@ -302,8 +302,7 @@ testTypedefSubtyping() {
|
||||
typedef int int__int_int(int i1, int i2);
|
||||
typedef void inline_void_(void f());
|
||||
typedef void inline_void__int(void f(int i));
|
||||
""");
|
||||
functionSubtypingHelper(env);
|
||||
""").then(functionSubtypingHelper));
|
||||
}
|
||||
|
||||
functionSubtypingHelper(TypeEnvironment env) {
|
||||
@@ -363,7 +362,7 @@ functionSubtypingHelper(TypeEnvironment env) {
|
||||
}
|
||||
|
||||
testFunctionSubtypingOptional() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
void void_() {}
|
||||
void void__int(int i) {}
|
||||
void void___int([int i]) {}
|
||||
@@ -376,12 +375,11 @@ testFunctionSubtypingOptional() {
|
||||
void void___int_int([int i1, int i2]) {}
|
||||
void void___int_int_int([int i1, int i2, int i3]);
|
||||
void void___Object_int([Object o, int i]) {}
|
||||
""");
|
||||
functionSubtypingOptionalHelper(env);
|
||||
""").then(functionSubtypingOptionalHelper));
|
||||
}
|
||||
|
||||
testTypedefSubtypingOptional() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
typedef void void_();
|
||||
typedef void void__int(int i);
|
||||
typedef void void___int([int i]);
|
||||
@@ -394,8 +392,7 @@ testTypedefSubtypingOptional() {
|
||||
typedef void void___int_int([int i1, int i2]);
|
||||
typedef void void___int_int_int([int i1, int i2, int i3]);
|
||||
typedef void void___Object_int([Object o, int i]);
|
||||
""");
|
||||
functionSubtypingOptionalHelper(env);
|
||||
""").then(functionSubtypingOptionalHelper));
|
||||
}
|
||||
|
||||
functionSubtypingOptionalHelper(TypeEnvironment env) {
|
||||
@@ -443,7 +440,7 @@ functionSubtypingOptionalHelper(TypeEnvironment env) {
|
||||
}
|
||||
|
||||
testFunctionSubtypingNamed() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
void void_() {}
|
||||
void void__int(int i) {}
|
||||
void void___a_int({int a}) {}
|
||||
@@ -458,12 +455,11 @@ testFunctionSubtypingNamed() {
|
||||
void void___a_int_c_int({int a, int c}) {}
|
||||
void void___b_int_c_int({int b, int c}) {}
|
||||
void void___c_int({int c}) {}
|
||||
""");
|
||||
functionSubtypingNamedHelper(env);
|
||||
""").then(functionSubtypingNamedHelper));
|
||||
}
|
||||
|
||||
testTypedefSubtypingNamed() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
typedef void void_();
|
||||
typedef void void__int(int i);
|
||||
typedef void void___a_int({int a});
|
||||
@@ -478,8 +474,7 @@ testTypedefSubtypingNamed() {
|
||||
typedef void void___a_int_c_int({int a, int c});
|
||||
typedef void void___b_int_c_int({int b, int c});
|
||||
typedef void void___c_int({int c});
|
||||
""");
|
||||
functionSubtypingNamedHelper(env);
|
||||
""").then(functionSubtypingNamedHelper));
|
||||
}
|
||||
|
||||
functionSubtypingNamedHelper(TypeEnvironment env) {
|
||||
@@ -521,7 +516,7 @@ functionSubtypingNamedHelper(TypeEnvironment env) {
|
||||
}
|
||||
|
||||
void testTypeVariableSubtype() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
class A<T> {}
|
||||
class B<T extends Object> {}
|
||||
class C<T extends num> {}
|
||||
@@ -532,207 +527,207 @@ void testTypeVariableSubtype() {
|
||||
class H<T extends S, S extends T> {}
|
||||
class I<T extends S, S extends U, U extends T> {}
|
||||
class J<T extends S, S extends U, U extends S> {}
|
||||
""");
|
||||
""").then((env) {
|
||||
void expect(bool value, DartType T, DartType S) {
|
||||
Expect.equals(value, env.isSubtype(T, S), '$T <: $S');
|
||||
}
|
||||
|
||||
void expect(bool value, DartType T, DartType S) {
|
||||
Expect.equals(value, env.isSubtype(T, S), '$T <: $S');
|
||||
}
|
||||
ClassElement A = env.getElement('A');
|
||||
TypeVariableType A_T = A.thisType.typeArguments.head;
|
||||
ClassElement B = env.getElement('B');
|
||||
TypeVariableType B_T = B.thisType.typeArguments.head;
|
||||
ClassElement C = env.getElement('C');
|
||||
TypeVariableType C_T = C.thisType.typeArguments.head;
|
||||
ClassElement D = env.getElement('D');
|
||||
TypeVariableType D_T = D.thisType.typeArguments.head;
|
||||
ClassElement E = env.getElement('E');
|
||||
TypeVariableType E_T = E.thisType.typeArguments.head;
|
||||
TypeVariableType E_S = E.thisType.typeArguments.tail.head;
|
||||
ClassElement F = env.getElement('F');
|
||||
TypeVariableType F_T = F.thisType.typeArguments.head;
|
||||
TypeVariableType F_S = F.thisType.typeArguments.tail.head;
|
||||
ClassElement G = env.getElement('G');
|
||||
TypeVariableType G_T = G.thisType.typeArguments.head;
|
||||
ClassElement H = env.getElement('H');
|
||||
TypeVariableType H_T = H.thisType.typeArguments.head;
|
||||
TypeVariableType H_S = H.thisType.typeArguments.tail.head;
|
||||
ClassElement I = env.getElement('I');
|
||||
TypeVariableType I_T = I.thisType.typeArguments.head;
|
||||
TypeVariableType I_S = I.thisType.typeArguments.tail.head;
|
||||
TypeVariableType I_U = I.thisType.typeArguments.tail.tail.head;
|
||||
ClassElement J = env.getElement('J');
|
||||
TypeVariableType J_T = J.thisType.typeArguments.head;
|
||||
TypeVariableType J_S = J.thisType.typeArguments.tail.head;
|
||||
TypeVariableType J_U = J.thisType.typeArguments.tail.tail.head;
|
||||
|
||||
ClassElement A = env.getElement('A');
|
||||
TypeVariableType A_T = A.thisType.typeArguments.head;
|
||||
ClassElement B = env.getElement('B');
|
||||
TypeVariableType B_T = B.thisType.typeArguments.head;
|
||||
ClassElement C = env.getElement('C');
|
||||
TypeVariableType C_T = C.thisType.typeArguments.head;
|
||||
ClassElement D = env.getElement('D');
|
||||
TypeVariableType D_T = D.thisType.typeArguments.head;
|
||||
ClassElement E = env.getElement('E');
|
||||
TypeVariableType E_T = E.thisType.typeArguments.head;
|
||||
TypeVariableType E_S = E.thisType.typeArguments.tail.head;
|
||||
ClassElement F = env.getElement('F');
|
||||
TypeVariableType F_T = F.thisType.typeArguments.head;
|
||||
TypeVariableType F_S = F.thisType.typeArguments.tail.head;
|
||||
ClassElement G = env.getElement('G');
|
||||
TypeVariableType G_T = G.thisType.typeArguments.head;
|
||||
ClassElement H = env.getElement('H');
|
||||
TypeVariableType H_T = H.thisType.typeArguments.head;
|
||||
TypeVariableType H_S = H.thisType.typeArguments.tail.head;
|
||||
ClassElement I = env.getElement('I');
|
||||
TypeVariableType I_T = I.thisType.typeArguments.head;
|
||||
TypeVariableType I_S = I.thisType.typeArguments.tail.head;
|
||||
TypeVariableType I_U = I.thisType.typeArguments.tail.tail.head;
|
||||
ClassElement J = env.getElement('J');
|
||||
TypeVariableType J_T = J.thisType.typeArguments.head;
|
||||
TypeVariableType J_S = J.thisType.typeArguments.tail.head;
|
||||
TypeVariableType J_U = J.thisType.typeArguments.tail.tail.head;
|
||||
DartType Object_ = env['Object'];
|
||||
DartType num_ = env['num'];
|
||||
DartType int_ = env['int'];
|
||||
DartType String_ = env['String'];
|
||||
DartType dynamic_ = env['dynamic'];
|
||||
|
||||
DartType Object_ = env['Object'];
|
||||
DartType num_ = env['num'];
|
||||
DartType int_ = env['int'];
|
||||
DartType String_ = env['String'];
|
||||
DartType dynamic_ = env['dynamic'];
|
||||
// class A<T> {}
|
||||
expect(true, A_T, Object_);
|
||||
expect(false, A_T, num_);
|
||||
expect(false, A_T, int_);
|
||||
expect(false, A_T, String_);
|
||||
expect(true, A_T, dynamic_);
|
||||
expect(true, A_T, A_T);
|
||||
expect(false, A_T, B_T);
|
||||
|
||||
// class A<T> {}
|
||||
expect(true, A_T, Object_);
|
||||
expect(false, A_T, num_);
|
||||
expect(false, A_T, int_);
|
||||
expect(false, A_T, String_);
|
||||
expect(true, A_T, dynamic_);
|
||||
expect(true, A_T, A_T);
|
||||
expect(false, A_T, B_T);
|
||||
// class B<T extends Object> {}
|
||||
expect(true, B_T, Object_);
|
||||
expect(false, B_T, num_);
|
||||
expect(false, B_T, int_);
|
||||
expect(false, B_T, String_);
|
||||
expect(true, B_T, dynamic_);
|
||||
expect(true, B_T, B_T);
|
||||
expect(false, B_T, A_T);
|
||||
|
||||
// class B<T extends Object> {}
|
||||
expect(true, B_T, Object_);
|
||||
expect(false, B_T, num_);
|
||||
expect(false, B_T, int_);
|
||||
expect(false, B_T, String_);
|
||||
expect(true, B_T, dynamic_);
|
||||
expect(true, B_T, B_T);
|
||||
expect(false, B_T, A_T);
|
||||
// class C<T extends num> {}
|
||||
expect(true, C_T, Object_);
|
||||
expect(true, C_T, num_);
|
||||
expect(false, C_T, int_);
|
||||
expect(false, C_T, String_);
|
||||
expect(true, C_T, dynamic_);
|
||||
expect(true, C_T, C_T);
|
||||
expect(false, C_T, A_T);
|
||||
|
||||
// class C<T extends num> {}
|
||||
expect(true, C_T, Object_);
|
||||
expect(true, C_T, num_);
|
||||
expect(false, C_T, int_);
|
||||
expect(false, C_T, String_);
|
||||
expect(true, C_T, dynamic_);
|
||||
expect(true, C_T, C_T);
|
||||
expect(false, C_T, A_T);
|
||||
// class D<T extends int> {}
|
||||
expect(true, D_T, Object_);
|
||||
expect(true, D_T, num_);
|
||||
expect(true, D_T, int_);
|
||||
expect(false, D_T, String_);
|
||||
expect(true, D_T, dynamic_);
|
||||
expect(true, D_T, D_T);
|
||||
expect(false, D_T, A_T);
|
||||
|
||||
// class D<T extends int> {}
|
||||
expect(true, D_T, Object_);
|
||||
expect(true, D_T, num_);
|
||||
expect(true, D_T, int_);
|
||||
expect(false, D_T, String_);
|
||||
expect(true, D_T, dynamic_);
|
||||
expect(true, D_T, D_T);
|
||||
expect(false, D_T, A_T);
|
||||
// class E<T extends S, S extends num> {}
|
||||
expect(true, E_T, Object_);
|
||||
expect(true, E_T, num_);
|
||||
expect(false, E_T, int_);
|
||||
expect(false, E_T, String_);
|
||||
expect(true, E_T, dynamic_);
|
||||
expect(true, E_T, E_T);
|
||||
expect(true, E_T, E_S);
|
||||
expect(false, E_T, A_T);
|
||||
|
||||
// class E<T extends S, S extends num> {}
|
||||
expect(true, E_T, Object_);
|
||||
expect(true, E_T, num_);
|
||||
expect(false, E_T, int_);
|
||||
expect(false, E_T, String_);
|
||||
expect(true, E_T, dynamic_);
|
||||
expect(true, E_T, E_T);
|
||||
expect(true, E_T, E_S);
|
||||
expect(false, E_T, A_T);
|
||||
expect(true, E_S, Object_);
|
||||
expect(true, E_S, num_);
|
||||
expect(false, E_S, int_);
|
||||
expect(false, E_S, String_);
|
||||
expect(true, E_S, dynamic_);
|
||||
expect(false, E_S, E_T);
|
||||
expect(true, E_S, E_S);
|
||||
expect(false, E_S, A_T);
|
||||
|
||||
expect(true, E_S, Object_);
|
||||
expect(true, E_S, num_);
|
||||
expect(false, E_S, int_);
|
||||
expect(false, E_S, String_);
|
||||
expect(true, E_S, dynamic_);
|
||||
expect(false, E_S, E_T);
|
||||
expect(true, E_S, E_S);
|
||||
expect(false, E_S, A_T);
|
||||
// class F<T extends num, S extends T> {}
|
||||
expect(true, F_T, Object_);
|
||||
expect(true, F_T, num_);
|
||||
expect(false, F_T, int_);
|
||||
expect(false, F_T, String_);
|
||||
expect(true, F_T, dynamic_);
|
||||
expect(false, F_T, F_S);
|
||||
expect(true, F_T, F_T);
|
||||
expect(false, F_T, A_T);
|
||||
|
||||
// class F<T extends num, S extends T> {}
|
||||
expect(true, F_T, Object_);
|
||||
expect(true, F_T, num_);
|
||||
expect(false, F_T, int_);
|
||||
expect(false, F_T, String_);
|
||||
expect(true, F_T, dynamic_);
|
||||
expect(false, F_T, F_S);
|
||||
expect(true, F_T, F_T);
|
||||
expect(false, F_T, A_T);
|
||||
expect(true, F_S, Object_);
|
||||
expect(true, F_S, num_);
|
||||
expect(false, F_S, int_);
|
||||
expect(false, F_S, String_);
|
||||
expect(true, F_S, dynamic_);
|
||||
expect(true, F_S, F_S);
|
||||
expect(true, F_S, F_T);
|
||||
expect(false, F_S, A_T);
|
||||
|
||||
expect(true, F_S, Object_);
|
||||
expect(true, F_S, num_);
|
||||
expect(false, F_S, int_);
|
||||
expect(false, F_S, String_);
|
||||
expect(true, F_S, dynamic_);
|
||||
expect(true, F_S, F_S);
|
||||
expect(true, F_S, F_T);
|
||||
expect(false, F_S, A_T);
|
||||
// class G<T extends T> {}
|
||||
expect(true, G_T, Object_);
|
||||
expect(false, G_T, num_);
|
||||
expect(false, G_T, int_);
|
||||
expect(false, G_T, String_);
|
||||
expect(true, G_T, dynamic_);
|
||||
expect(true, G_T, G_T);
|
||||
expect(false, G_T, A_T);
|
||||
|
||||
// class G<T extends T> {}
|
||||
expect(true, G_T, Object_);
|
||||
expect(false, G_T, num_);
|
||||
expect(false, G_T, int_);
|
||||
expect(false, G_T, String_);
|
||||
expect(true, G_T, dynamic_);
|
||||
expect(true, G_T, G_T);
|
||||
expect(false, G_T, A_T);
|
||||
// class H<T extends S, S extends T> {}
|
||||
expect(true, H_T, Object_);
|
||||
expect(false, H_T, num_);
|
||||
expect(false, H_T, int_);
|
||||
expect(false, H_T, String_);
|
||||
expect(true, H_T, dynamic_);
|
||||
expect(true, H_T, H_T);
|
||||
expect(true, H_T, H_S);
|
||||
expect(false, H_T, A_T);
|
||||
|
||||
// class H<T extends S, S extends T> {}
|
||||
expect(true, H_T, Object_);
|
||||
expect(false, H_T, num_);
|
||||
expect(false, H_T, int_);
|
||||
expect(false, H_T, String_);
|
||||
expect(true, H_T, dynamic_);
|
||||
expect(true, H_T, H_T);
|
||||
expect(true, H_T, H_S);
|
||||
expect(false, H_T, A_T);
|
||||
expect(true, H_S, Object_);
|
||||
expect(false, H_S, num_);
|
||||
expect(false, H_S, int_);
|
||||
expect(false, H_S, String_);
|
||||
expect(true, H_S, dynamic_);
|
||||
expect(true, H_S, H_T);
|
||||
expect(true, H_S, H_S);
|
||||
expect(false, H_S, A_T);
|
||||
|
||||
expect(true, H_S, Object_);
|
||||
expect(false, H_S, num_);
|
||||
expect(false, H_S, int_);
|
||||
expect(false, H_S, String_);
|
||||
expect(true, H_S, dynamic_);
|
||||
expect(true, H_S, H_T);
|
||||
expect(true, H_S, H_S);
|
||||
expect(false, H_S, A_T);
|
||||
// class I<T extends S, S extends U, U extends T> {}
|
||||
expect(true, I_T, Object_);
|
||||
expect(false, I_T, num_);
|
||||
expect(false, I_T, int_);
|
||||
expect(false, I_T, String_);
|
||||
expect(true, I_T, dynamic_);
|
||||
expect(true, I_T, I_T);
|
||||
expect(true, I_T, I_S);
|
||||
expect(true, I_T, I_U);
|
||||
expect(false, I_T, A_T);
|
||||
|
||||
// class I<T extends S, S extends U, U extends T> {}
|
||||
expect(true, I_T, Object_);
|
||||
expect(false, I_T, num_);
|
||||
expect(false, I_T, int_);
|
||||
expect(false, I_T, String_);
|
||||
expect(true, I_T, dynamic_);
|
||||
expect(true, I_T, I_T);
|
||||
expect(true, I_T, I_S);
|
||||
expect(true, I_T, I_U);
|
||||
expect(false, I_T, A_T);
|
||||
expect(true, I_S, Object_);
|
||||
expect(false, I_S, num_);
|
||||
expect(false, I_S, int_);
|
||||
expect(false, I_S, String_);
|
||||
expect(true, I_S, dynamic_);
|
||||
expect(true, I_S, I_T);
|
||||
expect(true, I_S, I_S);
|
||||
expect(true, I_S, I_U);
|
||||
expect(false, I_S, A_T);
|
||||
|
||||
expect(true, I_S, Object_);
|
||||
expect(false, I_S, num_);
|
||||
expect(false, I_S, int_);
|
||||
expect(false, I_S, String_);
|
||||
expect(true, I_S, dynamic_);
|
||||
expect(true, I_S, I_T);
|
||||
expect(true, I_S, I_S);
|
||||
expect(true, I_S, I_U);
|
||||
expect(false, I_S, A_T);
|
||||
expect(true, I_U, Object_);
|
||||
expect(false, I_U, num_);
|
||||
expect(false, I_U, int_);
|
||||
expect(false, I_U, String_);
|
||||
expect(true, I_U, dynamic_);
|
||||
expect(true, I_U, I_T);
|
||||
expect(true, I_U, I_S);
|
||||
expect(true, I_U, I_U);
|
||||
expect(false, I_U, A_T);
|
||||
|
||||
expect(true, I_U, Object_);
|
||||
expect(false, I_U, num_);
|
||||
expect(false, I_U, int_);
|
||||
expect(false, I_U, String_);
|
||||
expect(true, I_U, dynamic_);
|
||||
expect(true, I_U, I_T);
|
||||
expect(true, I_U, I_S);
|
||||
expect(true, I_U, I_U);
|
||||
expect(false, I_U, A_T);
|
||||
// class J<T extends S, S extends U, U extends S> {}
|
||||
expect(true, J_T, Object_);
|
||||
expect(false, J_T, num_);
|
||||
expect(false, J_T, int_);
|
||||
expect(false, J_T, String_);
|
||||
expect(true, J_T, dynamic_);
|
||||
expect(true, J_T, J_T);
|
||||
expect(true, J_T, J_S);
|
||||
expect(true, J_T, J_U);
|
||||
expect(false, J_T, A_T);
|
||||
|
||||
// class J<T extends S, S extends U, U extends S> {}
|
||||
expect(true, J_T, Object_);
|
||||
expect(false, J_T, num_);
|
||||
expect(false, J_T, int_);
|
||||
expect(false, J_T, String_);
|
||||
expect(true, J_T, dynamic_);
|
||||
expect(true, J_T, J_T);
|
||||
expect(true, J_T, J_S);
|
||||
expect(true, J_T, J_U);
|
||||
expect(false, J_T, A_T);
|
||||
expect(true, J_S, Object_);
|
||||
expect(false, J_S, num_);
|
||||
expect(false, J_S, int_);
|
||||
expect(false, J_S, String_);
|
||||
expect(true, J_S, dynamic_);
|
||||
expect(false, J_S, J_T);
|
||||
expect(true, J_S, J_S);
|
||||
expect(true, J_S, J_U);
|
||||
expect(false, J_S, A_T);
|
||||
|
||||
expect(true, J_S, Object_);
|
||||
expect(false, J_S, num_);
|
||||
expect(false, J_S, int_);
|
||||
expect(false, J_S, String_);
|
||||
expect(true, J_S, dynamic_);
|
||||
expect(false, J_S, J_T);
|
||||
expect(true, J_S, J_S);
|
||||
expect(true, J_S, J_U);
|
||||
expect(false, J_S, A_T);
|
||||
|
||||
expect(true, J_U, Object_);
|
||||
expect(false, J_U, num_);
|
||||
expect(false, J_U, int_);
|
||||
expect(false, J_U, String_);
|
||||
expect(true, J_U, dynamic_);
|
||||
expect(false, J_U, J_T);
|
||||
expect(true, J_U, J_S);
|
||||
expect(true, J_U, J_U);
|
||||
expect(false, J_U, A_T);
|
||||
expect(true, J_U, Object_);
|
||||
expect(false, J_U, num_);
|
||||
expect(false, J_U, int_);
|
||||
expect(false, J_U, String_);
|
||||
expect(true, J_U, dynamic_);
|
||||
expect(false, J_U, J_T);
|
||||
expect(true, J_U, J_S);
|
||||
expect(true, J_U, J_U);
|
||||
expect(false, J_U, A_T);
|
||||
}));
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
// Test of import tag to library mapping.
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const MAIN_CODE = """
|
||||
@@ -24,7 +25,7 @@ void main() {
|
||||
'library.dart': LIB_CODE,
|
||||
};
|
||||
|
||||
compileSources(sources, (MockCompiler compiler) {
|
||||
asyncTest(() => compileSources(sources, (MockCompiler compiler) {
|
||||
LibraryElement mainApp = compiler.libraries['source:/main.dart'];
|
||||
LibraryElement lib = compiler.libraries['source:/library.dart'];
|
||||
Expect.isNotNull(mainApp, 'Could not find main.dart library');
|
||||
@@ -36,5 +37,5 @@ void main() {
|
||||
// Test that we can get from the import tag in main.dart to the
|
||||
// library element representing library.dart.
|
||||
Expect.identical(lib, mainApp.getLibraryFromTag(tag));
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'compiler_helper.dart';
|
||||
|
||||
const String TEST = r"""
|
||||
@@ -25,8 +26,9 @@ main() {
|
||||
""";
|
||||
|
||||
void main() {
|
||||
String generated = compileAll(TEST);
|
||||
Expect.isTrue(generated.contains('return 42'));
|
||||
Expect.isTrue(generated.contains('return 54'));
|
||||
Expect.isFalse(generated.contains('return 68'));
|
||||
asyncTest(() => compileAll(TEST).then((generated) {
|
||||
Expect.isTrue(generated.contains('return 42'));
|
||||
Expect.isTrue(generated.contains('return 54'));
|
||||
Expect.isFalse(generated.contains('return 68'));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart';
|
||||
import "compiler_helper.dart";
|
||||
import "parser_helper.dart";
|
||||
@@ -87,30 +88,30 @@ void main() {
|
||||
""",
|
||||
uri,
|
||||
analyzeAll: true, analyzeOnly: true);
|
||||
compiler.runCompiler(uri);
|
||||
asyncTest(() => compiler.runCompiler(uri).then((_) {
|
||||
test(compiler, "void1", "void2", expect: true);
|
||||
test(compiler, "int1", "int2", expect: true);
|
||||
test(compiler, "String1", "String2", expect: true);
|
||||
test(compiler, "ListInt1", "ListInt2", expect: true);
|
||||
test(compiler, "ListString1", "ListString2", expect: true);
|
||||
test(compiler, "MapIntString1", "MapIntString2", expect: true);
|
||||
test(compiler, "TypeVar1", "TypeVar2", expect: true);
|
||||
test(compiler, "Function1a", "Function2a", expect: true);
|
||||
test(compiler, "Function1b", "Function2b", expect: true);
|
||||
test(compiler, "Typedef1a", "Typedef2a", expect: true);
|
||||
test(compiler, "Typedef1b", "Typedef2b", expect: true);
|
||||
test(compiler, "Typedef1c", "Typedef2c", expect: true);
|
||||
|
||||
test(compiler, "void1", "void2", expect: true);
|
||||
test(compiler, "int1", "int2", expect: true);
|
||||
test(compiler, "String1", "String2", expect: true);
|
||||
test(compiler, "ListInt1", "ListInt2", expect: true);
|
||||
test(compiler, "ListString1", "ListString2", expect: true);
|
||||
test(compiler, "MapIntString1", "MapIntString2", expect: true);
|
||||
test(compiler, "TypeVar1", "TypeVar2", expect: true);
|
||||
test(compiler, "Function1a", "Function2a", expect: true);
|
||||
test(compiler, "Function1b", "Function2b", expect: true);
|
||||
test(compiler, "Typedef1a", "Typedef2a", expect: true);
|
||||
test(compiler, "Typedef1b", "Typedef2b", expect: true);
|
||||
test(compiler, "Typedef1c", "Typedef2c", expect: true);
|
||||
|
||||
test(compiler, "void1", "int1", expect: false);
|
||||
test(compiler, "int1", "String1", expect: false);
|
||||
test(compiler, "String1", "ListInt1", expect: false);
|
||||
test(compiler, "ListInt1", "ListString1", expect: false);
|
||||
test(compiler, "ListString1", "MapIntString1", expect: false);
|
||||
test(compiler, "MapIntString1", "TypeVar1", expect: false);
|
||||
test(compiler, "TypeVar1", "Function1a", expect: false);
|
||||
test(compiler, "Function1a", "Function1b", expect: false);
|
||||
test(compiler, "Function1b", "Typedef1a", expect: false);
|
||||
test(compiler, "Typedef1a", "Typedef1b", expect: false);
|
||||
test(compiler, "Typedef1b", "Typedef1c", expect: false);
|
||||
test(compiler, "void1", "int1", expect: false);
|
||||
test(compiler, "int1", "String1", expect: false);
|
||||
test(compiler, "String1", "ListInt1", expect: false);
|
||||
test(compiler, "ListInt1", "ListString1", expect: false);
|
||||
test(compiler, "ListString1", "MapIntString1", expect: false);
|
||||
test(compiler, "MapIntString1", "TypeVar1", expect: false);
|
||||
test(compiler, "TypeVar1", "Function1a", expect: false);
|
||||
test(compiler, "Function1a", "Function1b", expect: false);
|
||||
test(compiler, "Function1b", "Typedef1a", expect: false);
|
||||
test(compiler, "Typedef1a", "Typedef1b", expect: false);
|
||||
test(compiler, "Typedef1b", "Typedef1c", expect: false);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
library subtype_test;
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import 'type_test_helper.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart';
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/js/js.dart';
|
||||
@@ -18,7 +19,7 @@ void main() {
|
||||
}
|
||||
|
||||
void testTypeRepresentations() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
typedef void Typedef();
|
||||
|
||||
void m1() {}
|
||||
@@ -31,133 +32,133 @@ void testTypeRepresentations() {
|
||||
m8(int a, {String b}) {}
|
||||
m9(int a, String b, {List<int> c, d}) {}
|
||||
m10(void f(int a, [b])) {}
|
||||
""");
|
||||
""").then((env) {
|
||||
TypeRepresentationGenerator typeRepresentation =
|
||||
new TypeRepresentationGenerator(env.compiler);
|
||||
|
||||
TypeRepresentationGenerator typeRepresentation =
|
||||
new TypeRepresentationGenerator(env.compiler);
|
||||
Expression onVariable(TypeVariableType variable) {
|
||||
return new VariableUse(variable.name.slowToString());
|
||||
}
|
||||
|
||||
Expression onVariable(TypeVariableType variable) {
|
||||
return new VariableUse(variable.name.slowToString());
|
||||
}
|
||||
String stringify(Expression expression) {
|
||||
return prettyPrint(expression, env.compiler).buffer.toString();
|
||||
}
|
||||
|
||||
String stringify(Expression expression) {
|
||||
return prettyPrint(expression, env.compiler).buffer.toString();
|
||||
}
|
||||
void expect(String expectedRepresentation, DartType type) {
|
||||
Expression expression =
|
||||
typeRepresentation.getTypeRepresentation(type, onVariable);
|
||||
Expect.stringEquals(expectedRepresentation, stringify(expression));
|
||||
}
|
||||
|
||||
void expect(String expectedRepresentation, DartType type) {
|
||||
Expression expression =
|
||||
typeRepresentation.getTypeRepresentation(type, onVariable);
|
||||
Expect.stringEquals(expectedRepresentation, stringify(expression));
|
||||
}
|
||||
String getJsName(ClassElement cls) {
|
||||
Expression name = typeRepresentation.getJavaScriptClassName(cls);
|
||||
return stringify(name);
|
||||
}
|
||||
|
||||
String getJsName(ClassElement cls) {
|
||||
Expression name = typeRepresentation.getJavaScriptClassName(cls);
|
||||
return stringify(name);
|
||||
}
|
||||
JavaScriptBackend backend = env.compiler.backend;
|
||||
String func = backend.namer.functionTypeTag();
|
||||
String retvoid = backend.namer.functionTypeVoidReturnTag();
|
||||
String ret = backend.namer.functionTypeReturnTypeTag();
|
||||
String args = backend.namer.functionTypeRequiredParametersTag();
|
||||
String opt = backend.namer.functionTypeOptionalParametersTag();
|
||||
String named = backend.namer.functionTypeNamedParametersTag();
|
||||
|
||||
JavaScriptBackend backend = env.compiler.backend;
|
||||
String func = backend.namer.functionTypeTag();
|
||||
String retvoid = backend.namer.functionTypeVoidReturnTag();
|
||||
String ret = backend.namer.functionTypeReturnTypeTag();
|
||||
String args = backend.namer.functionTypeRequiredParametersTag();
|
||||
String opt = backend.namer.functionTypeOptionalParametersTag();
|
||||
String named = backend.namer.functionTypeNamedParametersTag();
|
||||
ClassElement List_ = env.getElement('List');
|
||||
TypeVariableType List_E = List_.typeVariables.head;
|
||||
ClassElement Map_ = env.getElement('Map');
|
||||
TypeVariableType Map_K = Map_.typeVariables.head;
|
||||
TypeVariableType Map_V = Map_.typeVariables.tail.head;
|
||||
|
||||
ClassElement List_ = env.getElement('List');
|
||||
TypeVariableType List_E = List_.typeVariables.head;
|
||||
ClassElement Map_ = env.getElement('Map');
|
||||
TypeVariableType Map_K = Map_.typeVariables.head;
|
||||
TypeVariableType Map_V = Map_.typeVariables.tail.head;
|
||||
DartType Object_ = env['Object'];
|
||||
DartType int_ = env['int'];
|
||||
DartType String_ = env['String'];
|
||||
DartType dynamic_ = env['dynamic'];
|
||||
DartType Typedef_ = env['Typedef'];
|
||||
|
||||
DartType Object_ = env['Object'];
|
||||
DartType int_ = env['int'];
|
||||
DartType String_ = env['String'];
|
||||
DartType dynamic_ = env['dynamic'];
|
||||
DartType Typedef_ = env['Typedef'];
|
||||
String List_rep = getJsName(List_);
|
||||
String List_E_rep = stringify(onVariable(List_E));
|
||||
String Map_rep = getJsName(Map_);
|
||||
String Map_K_rep = stringify(onVariable(Map_K));
|
||||
String Map_V_rep = stringify(onVariable(Map_V));
|
||||
|
||||
String List_rep = getJsName(List_);
|
||||
String List_E_rep = stringify(onVariable(List_E));
|
||||
String Map_rep = getJsName(Map_);
|
||||
String Map_K_rep = stringify(onVariable(Map_K));
|
||||
String Map_V_rep = stringify(onVariable(Map_V));
|
||||
String Object_rep = getJsName(Object_.element);
|
||||
String int_rep = getJsName(int_.element);
|
||||
String String_rep = getJsName(String_.element);
|
||||
|
||||
String Object_rep = getJsName(Object_.element);
|
||||
String int_rep = getJsName(int_.element);
|
||||
String String_rep = getJsName(String_.element);
|
||||
expect('$int_rep', int_);
|
||||
expect('$String_rep', String_);
|
||||
expect('null', dynamic_);
|
||||
|
||||
expect('$int_rep', int_);
|
||||
expect('$String_rep', String_);
|
||||
expect('null', dynamic_);
|
||||
// List<E>
|
||||
expect('[$List_rep, $List_E_rep]', List_.computeType(env.compiler));
|
||||
// List
|
||||
expect('$List_rep', List_.rawType);
|
||||
// List<dynamic>
|
||||
expect('[$List_rep, null]', instantiate(List_, [dynamic_]));
|
||||
// List<int>
|
||||
expect('[$List_rep, $int_rep]', instantiate(List_, [int_]));
|
||||
// List<Typedef>
|
||||
expect('[$List_rep, {$func: "void_", $retvoid: true}]',
|
||||
instantiate(List_, [Typedef_]));
|
||||
|
||||
// List<E>
|
||||
expect('[$List_rep, $List_E_rep]', List_.computeType(env.compiler));
|
||||
// List
|
||||
expect('$List_rep', List_.rawType);
|
||||
// List<dynamic>
|
||||
expect('[$List_rep, null]', instantiate(List_, [dynamic_]));
|
||||
// List<int>
|
||||
expect('[$List_rep, $int_rep]', instantiate(List_, [int_]));
|
||||
// List<Typedef>
|
||||
expect('[$List_rep, {$func: "void_", $retvoid: true}]',
|
||||
instantiate(List_, [Typedef_]));
|
||||
// Map<K,V>
|
||||
expect('[$Map_rep, $Map_K_rep, $Map_V_rep]', Map_.computeType(env.compiler));
|
||||
// Map
|
||||
expect('$Map_rep', Map_.rawType);
|
||||
// Map<dynamic,dynamic>
|
||||
expect('[$Map_rep, null, null]', instantiate(Map_, [dynamic_, dynamic_]));
|
||||
// Map<int,String>
|
||||
expect('[$Map_rep, $int_rep, $String_rep]',
|
||||
instantiate(Map_, [int_, String_]));
|
||||
|
||||
// Map<K,V>
|
||||
expect('[$Map_rep, $Map_K_rep, $Map_V_rep]', Map_.computeType(env.compiler));
|
||||
// Map
|
||||
expect('$Map_rep', Map_.rawType);
|
||||
// Map<dynamic,dynamic>
|
||||
expect('[$Map_rep, null, null]', instantiate(Map_, [dynamic_, dynamic_]));
|
||||
// Map<int,String>
|
||||
expect('[$Map_rep, $int_rep, $String_rep]',
|
||||
instantiate(Map_, [int_, String_]));
|
||||
// void m1() {}
|
||||
expect('{$func: "void_", $retvoid: true}',
|
||||
env.getElement('m1').computeType(env.compiler));
|
||||
|
||||
// void m1() {}
|
||||
expect('{$func: "void_", $retvoid: true}',
|
||||
env.getElement('m1').computeType(env.compiler));
|
||||
// int m2() => 0;
|
||||
expect('{$func: "int_", $ret: $int_rep}',
|
||||
env.getElement('m2').computeType(env.compiler));
|
||||
|
||||
// int m2() => 0;
|
||||
expect('{$func: "int_", $ret: $int_rep}',
|
||||
env.getElement('m2').computeType(env.compiler));
|
||||
// List<int> m3() => null;
|
||||
expect('{$func: "List_", $ret: [$List_rep, $int_rep]}',
|
||||
env.getElement('m3').computeType(env.compiler));
|
||||
|
||||
// List<int> m3() => null;
|
||||
expect('{$func: "List_", $ret: [$List_rep, $int_rep]}',
|
||||
env.getElement('m3').computeType(env.compiler));
|
||||
// m4() {}
|
||||
expect('{$func: "args0"}',
|
||||
env.getElement('m4').computeType(env.compiler));
|
||||
|
||||
// m4() {}
|
||||
expect('{$func: "args0"}',
|
||||
env.getElement('m4').computeType(env.compiler));
|
||||
// m5(int a, String b) {}
|
||||
expect('{$func: "dynamic__int_String", $args: [$int_rep, $String_rep]}',
|
||||
env.getElement('m5').computeType(env.compiler));
|
||||
|
||||
// m5(int a, String b) {}
|
||||
expect('{$func: "dynamic__int_String", $args: [$int_rep, $String_rep]}',
|
||||
env.getElement('m5').computeType(env.compiler));
|
||||
// m6(int a, [String b]) {}
|
||||
expect('{$func: "dynamic__int__String", $args: [$int_rep],'
|
||||
' $opt: [$String_rep]}',
|
||||
env.getElement('m6').computeType(env.compiler));
|
||||
|
||||
// m6(int a, [String b]) {}
|
||||
expect('{$func: "dynamic__int__String", $args: [$int_rep],'
|
||||
' $opt: [$String_rep]}',
|
||||
env.getElement('m6').computeType(env.compiler));
|
||||
// m7(int a, String b, [List<int> c, d]) {}
|
||||
expect('{$func: "dynamic__int_String__List_dynamic",'
|
||||
' $args: [$int_rep, $String_rep],'
|
||||
' $opt: [[$List_rep, $int_rep], null]}',
|
||||
env.getElement('m7').computeType(env.compiler));
|
||||
|
||||
// m7(int a, String b, [List<int> c, d]) {}
|
||||
expect('{$func: "dynamic__int_String__List_dynamic",'
|
||||
' $args: [$int_rep, $String_rep],'
|
||||
' $opt: [[$List_rep, $int_rep], null]}',
|
||||
env.getElement('m7').computeType(env.compiler));
|
||||
// m8(int a, {String b}) {}
|
||||
expect('{$func: "dynamic__int__String0",'
|
||||
' $args: [$int_rep], $named: {b: $String_rep}}',
|
||||
env.getElement('m8').computeType(env.compiler));
|
||||
|
||||
// m8(int a, {String b}) {}
|
||||
expect('{$func: "dynamic__int__String0",'
|
||||
' $args: [$int_rep], $named: {b: $String_rep}}',
|
||||
env.getElement('m8').computeType(env.compiler));
|
||||
// m9(int a, String b, {List<int> c, d}) {}
|
||||
expect('{$func: "dynamic__int_String__List_dynamic0",'
|
||||
' $args: [$int_rep, $String_rep],'
|
||||
' $named: {c: [$List_rep, $int_rep], d: null}}',
|
||||
env.getElement('m9').computeType(env.compiler));
|
||||
|
||||
// m9(int a, String b, {List<int> c, d}) {}
|
||||
expect('{$func: "dynamic__int_String__List_dynamic0",'
|
||||
' $args: [$int_rep, $String_rep],'
|
||||
' $named: {c: [$List_rep, $int_rep], d: null}}',
|
||||
env.getElement('m9').computeType(env.compiler));
|
||||
|
||||
// m10(void f(int a, [b])) {}
|
||||
expect('{$func: "dynamic__void__int__dynamic", $args:'
|
||||
' [{$func: "void__int__dynamic",'
|
||||
' $retvoid: true, $args: [$int_rep], $opt: [null]}]}',
|
||||
env.getElement('m10').computeType(env.compiler));
|
||||
// m10(void f(int a, [b])) {}
|
||||
expect('{$func: "dynamic__void__int__dynamic", $args:'
|
||||
' [{$func: "void__int__dynamic",'
|
||||
' $retvoid: true, $args: [$int_rep], $opt: [null]}]}',
|
||||
env.getElement('m10').computeType(env.compiler));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
library type_substitution_test;
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart';
|
||||
import "compiler_helper.dart";
|
||||
import "parser_helper.dart";
|
||||
@@ -48,43 +49,46 @@ void main() {
|
||||
}
|
||||
|
||||
void testAsInstanceOf() {
|
||||
var env = new TypeEnvironment('''
|
||||
asyncTest(() => TypeEnvironment.create('''
|
||||
class A<T> {}
|
||||
class B<T> {}
|
||||
class C<T> extends A<T> {}
|
||||
class D<T> extends A<int> {}
|
||||
class E<T> extends A<A<T>> {}
|
||||
class F<T, U> extends B<F<T, String>> implements A<F<B<U>, int>> {}''');
|
||||
var compiler = env.compiler;
|
||||
class F<T, U> extends B<F<T, String>> implements A<F<B<U>, int>> {}
|
||||
''').then((env) {
|
||||
var compiler = env.compiler;
|
||||
|
||||
ClassElement A = env.getElement("A");
|
||||
ClassElement B = env.getElement("B");
|
||||
ClassElement C = env.getElement("C");
|
||||
ClassElement D = env.getElement("D");
|
||||
ClassElement E = env.getElement("E");
|
||||
ClassElement F = env.getElement("F");
|
||||
ClassElement A = env.getElement("A");
|
||||
ClassElement B = env.getElement("B");
|
||||
ClassElement C = env.getElement("C");
|
||||
ClassElement D = env.getElement("D");
|
||||
ClassElement E = env.getElement("E");
|
||||
ClassElement F = env.getElement("F");
|
||||
|
||||
DartType numType = env['num'];
|
||||
DartType intType = env['int'];
|
||||
DartType stringType = env['String'];
|
||||
DartType numType = env['num'];
|
||||
DartType intType = env['int'];
|
||||
DartType stringType = env['String'];
|
||||
|
||||
InterfaceType C_int = instantiate(C, [intType]);
|
||||
Expect.equals(instantiate(C, [intType]), C_int);
|
||||
Expect.equals(instantiate(A, [intType]), C_int.asInstanceOf(A));
|
||||
InterfaceType C_int = instantiate(C, [intType]);
|
||||
Expect.equals(instantiate(C, [intType]), C_int);
|
||||
Expect.equals(instantiate(A, [intType]), C_int.asInstanceOf(A));
|
||||
|
||||
InterfaceType D_int = instantiate(D, [stringType]);
|
||||
Expect.equals(instantiate(A, [intType]), D_int.asInstanceOf(A));
|
||||
InterfaceType D_int = instantiate(D, [stringType]);
|
||||
Expect.equals(instantiate(A, [intType]), D_int.asInstanceOf(A));
|
||||
|
||||
InterfaceType E_int = instantiate(E, [intType]);
|
||||
Expect.equals(instantiate(A, [instantiate(A, [intType])]),
|
||||
E_int.asInstanceOf(A));
|
||||
InterfaceType E_int = instantiate(E, [intType]);
|
||||
Expect.equals(instantiate(A, [instantiate(A, [intType])]),
|
||||
E_int.asInstanceOf(A));
|
||||
|
||||
InterfaceType F_int_string = instantiate(F, [intType, stringType]);
|
||||
Expect.equals(instantiate(B, [instantiate(F, [intType, stringType])]),
|
||||
F_int_string.asInstanceOf(B));
|
||||
Expect.equals(instantiate(A, [instantiate(F, [instantiate(B, [stringType]),
|
||||
intType])]),
|
||||
F_int_string.asInstanceOf(A));
|
||||
InterfaceType F_int_string = instantiate(F, [intType, stringType]);
|
||||
Expect.equals(instantiate(B, [instantiate(F, [intType, stringType])]),
|
||||
F_int_string.asInstanceOf(B));
|
||||
Expect.equals(instantiate(A, [instantiate(F, [instantiate(B, [stringType]),
|
||||
intType])]),
|
||||
F_int_string.asInstanceOf(A));
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +105,7 @@ bool testSubstitution(compiler, arguments, parameters,
|
||||
}
|
||||
|
||||
void testTypeSubstitution() {
|
||||
var env = new TypeEnvironment(r"""
|
||||
asyncTest(() => TypeEnvironment.create(r"""
|
||||
typedef void Typedef1<X,Y>(X x1, Y y2);
|
||||
typedef void Typedef2<Z>(Z z1);
|
||||
|
||||
@@ -153,78 +157,79 @@ void testTypeSubstitution() {
|
||||
void Typedef1e(Typedef2<S> a) {}
|
||||
void Typedef2e(Typedef2<String> b) {}
|
||||
}
|
||||
""");
|
||||
var compiler = env.compiler;
|
||||
""").then((env) {
|
||||
var compiler = env.compiler;
|
||||
|
||||
InterfaceType Class_T_S = env["Class"];
|
||||
Expect.isNotNull(Class_T_S);
|
||||
Expect.identical(Class_T_S.kind, TypeKind.INTERFACE);
|
||||
Expect.equals(2, length(Class_T_S.typeArguments));
|
||||
InterfaceType Class_T_S = env["Class"];
|
||||
Expect.isNotNull(Class_T_S);
|
||||
Expect.identical(Class_T_S.kind, TypeKind.INTERFACE);
|
||||
Expect.equals(2, length(Class_T_S.typeArguments));
|
||||
|
||||
DartType T = Class_T_S.typeArguments.head;
|
||||
Expect.isNotNull(T);
|
||||
Expect.identical(T.kind, TypeKind.TYPE_VARIABLE);
|
||||
DartType T = Class_T_S.typeArguments.head;
|
||||
Expect.isNotNull(T);
|
||||
Expect.identical(T.kind, TypeKind.TYPE_VARIABLE);
|
||||
|
||||
DartType S = Class_T_S.typeArguments.tail.head;
|
||||
Expect.isNotNull(S);
|
||||
Expect.identical(S.kind, TypeKind.TYPE_VARIABLE);
|
||||
DartType S = Class_T_S.typeArguments.tail.head;
|
||||
Expect.isNotNull(S);
|
||||
Expect.identical(S.kind, TypeKind.TYPE_VARIABLE);
|
||||
|
||||
DartType intType = env['int'];//getType(compiler, "int1");
|
||||
Expect.isNotNull(intType);
|
||||
Expect.identical(intType.kind, TypeKind.INTERFACE);
|
||||
DartType intType = env['int'];//getType(compiler, "int1");
|
||||
Expect.isNotNull(intType);
|
||||
Expect.identical(intType.kind, TypeKind.INTERFACE);
|
||||
|
||||
DartType StringType = env['String'];//getType(compiler, "String1");
|
||||
Expect.isNotNull(StringType);
|
||||
Expect.identical(StringType.kind, TypeKind.INTERFACE);
|
||||
DartType StringType = env['String'];//getType(compiler, "String1");
|
||||
Expect.isNotNull(StringType);
|
||||
Expect.identical(StringType.kind, TypeKind.INTERFACE);
|
||||
|
||||
var parameters = new Link<DartType>.fromList(<DartType>[T, S]);
|
||||
var arguments = new Link<DartType>.fromList(<DartType>[intType, StringType]);
|
||||
var parameters = new Link<DartType>.fromList(<DartType>[T, S]);
|
||||
var arguments = new Link<DartType>.fromList(<DartType>[intType, StringType]);
|
||||
|
||||
// TODO(johnniwinther): Create types directly from strings to improve test
|
||||
// readability.
|
||||
// TODO(johnniwinther): Create types directly from strings to improve test
|
||||
// readability.
|
||||
|
||||
testSubstitution(compiler, arguments, parameters, "void1", "void2");
|
||||
testSubstitution(compiler, arguments, parameters, "dynamic1", "dynamic2");
|
||||
testSubstitution(compiler, arguments, parameters, "int1", "int2");
|
||||
testSubstitution(compiler, arguments, parameters, "String1", "String2");
|
||||
testSubstitution(compiler, arguments, parameters, "ListInt1", "ListInt2");
|
||||
testSubstitution(compiler, arguments, parameters, "ListT1", "ListT2");
|
||||
testSubstitution(compiler, arguments, parameters, "ListS1", "ListS2");
|
||||
testSubstitution(compiler, arguments, parameters, "ListListT1", "ListListT2");
|
||||
testSubstitution(compiler, arguments, parameters, "ListRaw1", "ListRaw2");
|
||||
testSubstitution(compiler, arguments, parameters,
|
||||
"ListDynamic1", "ListDynamic2");
|
||||
testSubstitution(compiler, arguments, parameters,
|
||||
"MapIntString1", "MapIntString2");
|
||||
testSubstitution(compiler, arguments, parameters,
|
||||
"MapTString1", "MapTString2");
|
||||
testSubstitution(compiler, arguments, parameters,
|
||||
"MapDynamicString1", "MapDynamicString2");
|
||||
testSubstitution(compiler, arguments, parameters, "TypeVarT1", "TypeVarT2");
|
||||
testSubstitution(compiler, arguments, parameters, "TypeVarS1", "TypeVarS2");
|
||||
testSubstitution(compiler, arguments, parameters, "Function1a", "Function2a");
|
||||
testSubstitution(compiler, arguments, parameters, "Function1b", "Function2b");
|
||||
testSubstitution(compiler, arguments, parameters, "Function1c", "Function2c");
|
||||
testSubstitution(compiler, arguments, parameters, "Typedef1a", "Typedef2a");
|
||||
testSubstitution(compiler, arguments, parameters, "Typedef1b", "Typedef2b");
|
||||
testSubstitution(compiler, arguments, parameters, "Typedef1c", "Typedef2c");
|
||||
testSubstitution(compiler, arguments, parameters, "Typedef1d", "Typedef2d");
|
||||
testSubstitution(compiler, arguments, parameters, "Typedef1e", "Typedef2e");
|
||||
testSubstitution(compiler, arguments, parameters, "void1", "void2");
|
||||
testSubstitution(compiler, arguments, parameters, "dynamic1", "dynamic2");
|
||||
testSubstitution(compiler, arguments, parameters, "int1", "int2");
|
||||
testSubstitution(compiler, arguments, parameters, "String1", "String2");
|
||||
testSubstitution(compiler, arguments, parameters, "ListInt1", "ListInt2");
|
||||
testSubstitution(compiler, arguments, parameters, "ListT1", "ListT2");
|
||||
testSubstitution(compiler, arguments, parameters, "ListS1", "ListS2");
|
||||
testSubstitution(compiler, arguments, parameters, "ListListT1", "ListListT2");
|
||||
testSubstitution(compiler, arguments, parameters, "ListRaw1", "ListRaw2");
|
||||
testSubstitution(compiler, arguments, parameters,
|
||||
"ListDynamic1", "ListDynamic2");
|
||||
testSubstitution(compiler, arguments, parameters,
|
||||
"MapIntString1", "MapIntString2");
|
||||
testSubstitution(compiler, arguments, parameters,
|
||||
"MapTString1", "MapTString2");
|
||||
testSubstitution(compiler, arguments, parameters,
|
||||
"MapDynamicString1", "MapDynamicString2");
|
||||
testSubstitution(compiler, arguments, parameters, "TypeVarT1", "TypeVarT2");
|
||||
testSubstitution(compiler, arguments, parameters, "TypeVarS1", "TypeVarS2");
|
||||
testSubstitution(compiler, arguments, parameters, "Function1a", "Function2a");
|
||||
testSubstitution(compiler, arguments, parameters, "Function1b", "Function2b");
|
||||
testSubstitution(compiler, arguments, parameters, "Function1c", "Function2c");
|
||||
testSubstitution(compiler, arguments, parameters, "Typedef1a", "Typedef2a");
|
||||
testSubstitution(compiler, arguments, parameters, "Typedef1b", "Typedef2b");
|
||||
testSubstitution(compiler, arguments, parameters, "Typedef1c", "Typedef2c");
|
||||
testSubstitution(compiler, arguments, parameters, "Typedef1d", "Typedef2d");
|
||||
testSubstitution(compiler, arguments, parameters, "Typedef1e", "Typedef2e");
|
||||
|
||||
// Substitution in unalias.
|
||||
DartType Typedef2_int_String = getType(compiler, "Typedef2a");
|
||||
Expect.isNotNull(Typedef2_int_String);
|
||||
DartType Function_int_String = getType(compiler, "Function2b");
|
||||
Expect.isNotNull(Function_int_String);
|
||||
DartType unalias1 = Typedef2_int_String.unalias(compiler);
|
||||
Expect.equals(Function_int_String, unalias1,
|
||||
'$Typedef2_int_String.unalias=$unalias1 != $Function_int_String');
|
||||
// Substitution in unalias.
|
||||
DartType Typedef2_int_String = getType(compiler, "Typedef2a");
|
||||
Expect.isNotNull(Typedef2_int_String);
|
||||
DartType Function_int_String = getType(compiler, "Function2b");
|
||||
Expect.isNotNull(Function_int_String);
|
||||
DartType unalias1 = Typedef2_int_String.unalias(compiler);
|
||||
Expect.equals(Function_int_String, unalias1,
|
||||
'$Typedef2_int_String.unalias=$unalias1 != $Function_int_String');
|
||||
|
||||
DartType Typedef1 = getType(compiler, "Typedef1c");
|
||||
Expect.isNotNull(Typedef1);
|
||||
DartType Function_dynamic_dynamic = getType(compiler, "Function1c");
|
||||
Expect.isNotNull(Function_dynamic_dynamic);
|
||||
DartType unalias2 = Typedef1.unalias(compiler);
|
||||
Expect.equals(Function_dynamic_dynamic, unalias2,
|
||||
'$Typedef1.unalias=$unalias2 != $Function_dynamic_dynamic');
|
||||
DartType Typedef1 = getType(compiler, "Typedef1c");
|
||||
Expect.isNotNull(Typedef1);
|
||||
DartType Function_dynamic_dynamic = getType(compiler, "Function1c");
|
||||
Expect.isNotNull(Function_dynamic_dynamic);
|
||||
DartType unalias2 = Typedef1.unalias(compiler);
|
||||
Expect.equals(Function_dynamic_dynamic, unalias2,
|
||||
'$Typedef1.unalias=$unalias2 != $Function_dynamic_dynamic');
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
library type_test_helper;
|
||||
|
||||
import 'dart:async';
|
||||
import "package:expect/expect.dart";
|
||||
import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart';
|
||||
import "parser_helper.dart" show SourceString;
|
||||
@@ -22,7 +23,7 @@ GenericType instantiate(TypeDeclarationElement element,
|
||||
class TypeEnvironment {
|
||||
final MockCompiler compiler;
|
||||
|
||||
factory TypeEnvironment(String source) {
|
||||
static Future<TypeEnvironment> create(String source) {
|
||||
var uri = new Uri(scheme: 'source');
|
||||
MockCompiler compiler = compilerFor('''
|
||||
main() {}
|
||||
@@ -30,8 +31,9 @@ class TypeEnvironment {
|
||||
uri,
|
||||
analyzeAll: true,
|
||||
analyzeOnly: true);
|
||||
compiler.runCompiler(uri);
|
||||
return new TypeEnvironment._(compiler);
|
||||
return compiler.runCompiler(uri).then((_) {
|
||||
return new TypeEnvironment._(compiler);
|
||||
});
|
||||
}
|
||||
|
||||
TypeEnvironment._(MockCompiler this.compiler);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user