Skip to content

Commit

Permalink
fixes #184, type literals now use emitTypeName
Browse files Browse the repository at this point in the history
this fixes `dart.dynamic` as well as other cases covered by emitTypeName

R=vsm@google.com

Review URL: https://codereview.chromium.org/1142713004
  • Loading branch information
John Messerly committed May 18, 2015
1 parent 01d39ba commit 08fb216
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/dev_compiler/lib/src/codegen/js_codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,13 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {

var name = element.name;

// type literal
if (element is ClassElement ||
element is DynamicElementImpl ||
element is FunctionTypeAliasElement) {
return _emitTypeName(fillDynamicTypeArgs(element.type, types));
}

// library member
if (element.enclosingElement is CompilationUnitElement) {
return _maybeQualifiedName(
Expand Down
9 changes: 6 additions & 3 deletions pkg/dev_compiler/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,12 @@ Object getConstantField(
return (f == null || f.type != expectedType) ? null : f.value;
}

ParameterizedType fillDynamicTypeArgs(ParameterizedType t, TypeProvider types) {
var dyn = new List.filled(t.typeArguments.length, types.dynamicType);
return t.substitute2(dyn, t.typeArguments);
DartType fillDynamicTypeArgs(DartType t, TypeProvider types) {
if (t is ParameterizedType) {
var dyn = new List.filled(t.typeArguments.length, types.dynamicType);
return t.substitute2(dyn, t.typeArguments);
}
return t;
}

/// Similar to [SimpleIdentifier] inGetterContext, inSetterContext, and
Expand Down
15 changes: 15 additions & 0 deletions pkg/dev_compiler/test/codegen/expect/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@ var core = dart.import(core);
}
}
let UNINITIALIZED = dart.const(new _Uninitialized());
let Generic$ = dart.generic(function(T) {
class Generic extends core.Object {
get type() {
return Generic$();
}
}
return Generic;
});
let Generic = Generic$();
// Function main: () → dynamic
function main() {
core.print(dart.toString(1));
core.print(dart.toString(1.0));
core.print(dart.toString(1.1));
let x = 42;
core.print(dart.equals(x, dart.dynamic));
core.print(dart.equals(x, Generic));
core.print(new (Generic$(core.int))().type);
}
// Exports:
exports.UNINITIALIZED = UNINITIALIZED;
exports.Generic$ = Generic$;
exports.Generic = Generic;
exports.main = main;
})(misc, core);
12 changes: 12 additions & 0 deletions pkg/dev_compiler/test/codegen/misc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@
const UNINITIALIZED = const _Uninitialized();
class _Uninitialized { const _Uninitialized(); }

class Generic<T> {
Type get type => Generic;
}

main() {
// Number literals in call expressions.
print(1.toString());
print(1.0.toString());
print(1.1.toString());

// Type literals, #184
dynamic x = 42;
print(x == dynamic);
print(x == Generic);

// Should be Generic<dynamic>
print(new Generic<int>().type);
}

0 comments on commit 08fb216

Please sign in to comment.