Skip to content

Commit 1cc27c0

Browse files
committed
build
1 parent 95ae604 commit 1cc27c0

15 files changed

+128
-17
lines changed

assets/js/web.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ window.addEventListener('load', function(e) {
7575
if(getOptimizationLevel() > 0) {
7676
o.setup([ "lto", "no-assert", "fold-const", "return-if", "inline", "fold-const", "array-length" ]);
7777
emitter.setEnableRunTimeTypeCheck(false);
78-
optimizer.setEnableRunTimeTypeCheck(false);
78+
o.setEnableRunTimeTypeCheck(false);
7979
}
8080
c.setOptimizer(o);
8181

build/jsx-compiler.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ var ClassDefinition = exports.ClassDefinition = Class.extend({
756756
isConvertibleTo: function (classDef) {
757757
if (this == classDef)
758758
return true;
759+
if (classDef.className() == "Object")
760+
return true;
759761
if (this._extendType != null && this._extendType.getClassDef().isConvertibleTo(classDef))
760762
return true;
761763
for (var i = 0; i < this._implementTypes.length; ++i)
@@ -2784,7 +2786,10 @@ var ArrayLiteralExpression = exports.ArrayLiteralExpression = Expression.extend(
27842786
} else {
27852787
for (var i = 0; i < this._exprs.length; ++i) {
27862788
var elementType = this._exprs[i].getType().resolveIfMayBeUndefined();
2787-
if (! elementType.equals(Type.nullType)) {
2789+
if (elementType.equals(Type.nullType)
2790+
|| elementType.equals(Type.undefinedType)) {
2791+
// skip
2792+
} else {
27882793
if (elementType.equals(Type.integerType))
27892794
elementType = Type.numberType;
27902795
var instantiatedClass = context.instantiateTemplate(context.errors, new TemplateInstantiationRequest(this._token, "Array", [ elementType ]));
@@ -2800,7 +2805,7 @@ var ArrayLiteralExpression = exports.ArrayLiteralExpression = Expression.extend(
28002805
}
28012806
}
28022807
// check type of the elements
2803-
var expectedType = this._type.getClassDef().getTypeArguments()[0];
2808+
var expectedType = this._type.getClassDef().getTypeArguments()[0].toMayBeUndefinedType();
28042809
for (var i = 0; i < this._exprs.length; ++i) {
28052810
var elementType = this._exprs[i].getType();
28062811
if (! elementType.isConvertibleTo(expectedType)) {
@@ -9358,6 +9363,9 @@ var Parser = exports.Parser = Class.extend({
93589363
if (token.getValue() == "variant") {
93599364
this._errors.push(new CompileError(token, "cannot use 'variant' as a class name"));
93609365
return null;
9366+
} else if (token.getValue() == "MayBeUndefined") {
9367+
this._errors.push(new CompileError(token, "cannot use 'MayBeUndefined' as a class name"));
9368+
return null;
93619369
}
93629370
var imprt = this.lookupImportAlias(token.getValue());
93639371
if (imprt != null) {
@@ -9785,6 +9793,10 @@ var Parser = exports.Parser = Class.extend({
97859793
while (this._expectOpt("[") != null) {
97869794
if ((token = this._expect("]")) == null)
97879795
return false;
9796+
if (typeDecl instanceof MayBeUndefinedType) {
9797+
this._newError("MayBeUndefined.<T> cannot be an array, should be: T[]");
9798+
return null;
9799+
}
97889800
typeDecl = this._registerArrayTypeOf(token, typeDecl);
97899801
}
97909802
return typeDecl;
@@ -9874,10 +9886,10 @@ var Parser = exports.Parser = Class.extend({
98749886
if (token == null)
98759887
return null;
98769888
} while (token.getValue() == ",");
9877-
// disallow MayBeUndefined in template types (for the only existing types: MayBeUndefined, Array, Map)
9878-
if (types[0] instanceof MayBeUndefinedType) {
9879-
this._newError("type argument for class '" + qualifiedName.getToken().getValue() + "' cannot be a MayBeUndefined type");
9880-
return null;
9889+
// check
9890+
if (qualifiedName.getToken().getValue() == "Array" && types[0] instanceof MayBeUndefinedType) {
9891+
this._newError("cannot declare Array.<MayBeUndefined.<T>>, should be Array.<T>");
9892+
return false;
98819893
}
98829894
// request template instantiation (deferred)
98839895
this._templateInstantiationRequests.push(new TemplateInstantiationRequest(token, qualifiedName.getToken().getValue(), types));
@@ -13527,6 +13539,10 @@ var ParsedObjectType = exports.ParsedObjectType = ObjectType.extend({
1352713539
for (var i = 0; i < this._typeArguments.length; ++i) {
1352813540
var actualType = instantiationContext.typemap[this._typeArguments[i].toString()];
1352913541
typeArgs[i] = actualType != undefined ? actualType : this._typeArguments[i];
13542+
// special handling for Array.<T> (T should not be MayBeUndefinedType)
13543+
if (typeArgs[i] instanceof MayBeUndefinedType && this._qualifiedName.getToken().getValue() == "Array") {
13544+
typeArgs[i] = typeArgs[i].getBaseType();
13545+
}
1353013546
}
1353113547
instantiationContext.request.getInstantiationRequests().push(
1353213548
new TemplateInstantiationRequest(this._qualifiedName.getToken(), this._qualifiedName.getToken().getValue(), typeArgs));

index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
<li class="source-file"><a href="t/run/028.arrayfunc.jsx" data-path="t/run/028.arrayfunc.jsx">028.arrayfunc.jsx</a></li>
111111
<li class="source-file"><a href="t/run/029.hashfunc.jsx" data-path="t/run/029.hashfunc.jsx">029.hashfunc.jsx</a></li>
112112
<li class="source-file"><a href="t/run/031.overload.jsx" data-path="t/run/031.overload.jsx">031.overload.jsx</a></li>
113-
<li class="source-file"><a href="t/run/032.nested-maybeundefined.jsx" data-path="t/run/032.nested-maybeundefined.jsx">032.nested-maybeundefined.jsx</a></li>
114113
<li class="source-file"><a href="t/run/033.many-class.jsx" data-path="t/run/033.many-class.jsx">033.many-class.jsx</a></li>
115114
<li class="source-file"><a href="t/run/034.as.jsx" data-path="t/run/034.as.jsx">034.as.jsx</a></li>
116115
<li class="source-file"><a href="t/run/035.assign-to-int.jsx" data-path="t/run/035.assign-to-int.jsx">035.assign-to-int.jsx</a></li>
@@ -256,6 +255,9 @@
256255
<li class="source-file"><a href="t/run/170.cast-int-in-return.jsx" data-path="t/run/170.cast-int-in-return.jsx">170.cast-int-in-return.jsx</a></li>
257256
<li class="source-file"><a href="t/run/171.fused-div-of-int.jsx" data-path="t/run/171.fused-div-of-int.jsx">171.fused-div-of-int.jsx</a></li>
258257
<li class="source-file"><a href="t/run/172.profile.jsx" data-path="t/run/172.profile.jsx">172.profile.jsx</a></li>
258+
<li class="source-file"><a href="t/run/173.interface-or-mixin-as-object.jsx" data-path="t/run/173.interface-or-mixin-as-object.jsx">173.interface-or-mixin-as-object.jsx</a></li>
259+
<li class="source-file"><a href="t/run/174.undefined-in-array-literal.jsx" data-path="t/run/174.undefined-in-array-literal.jsx">174.undefined-in-array-literal.jsx</a></li>
260+
<li class="source-file"><a href="t/run/175.T-of-ArrayT-should-never-be-maybeundef.jsx" data-path="t/run/175.T-of-ArrayT-should-never-be-maybeundef.jsx">175.T-of-ArrayT-should-never-be-maybeundef.jsx</a></li>
259261
<li id="t-lib" class="nav-header">t/lib</li>
260262
<li class="source-file"><a href="t/lib/001.hello.jsx" data-path="t/lib/001.hello.jsx">001.hello.jsx</a></li>
261263
<li class="source-file"><a href="t/lib/002.timer.jsx" data-path="t/lib/002.timer.jsx">002.timer.jsx</a></li>
@@ -404,6 +406,9 @@
404406
<li class="source-file"><a href="t/compile_error/135.open-function.jsx" data-path="t/compile_error/135.open-function.jsx">135.open-function.jsx</a></li>
405407
<li class="source-file"><a href="t/compile_error/137.call-constructor-as-func.jsx" data-path="t/compile_error/137.call-constructor-as-func.jsx">137.call-constructor-as-func.jsx</a></li>
406408
<li class="source-file"><a href="t/compile_error/138.inner-function-declaration-wo-type.jsx" data-path="t/compile_error/138.inner-function-declaration-wo-type.jsx">138.inner-function-declaration-wo-type.jsx</a></li>
409+
<li class="source-file"><a href="t/compile_error/139.nested-maybeundefined.jsx" data-path="t/compile_error/139.nested-maybeundefined.jsx">139.nested-maybeundefined.jsx</a></li>
410+
<li class="source-file"><a href="t/compile_error/140.array-maybeundefined-t.jsx" data-path="t/compile_error/140.array-maybeundefined-t.jsx">140.array-maybeundefined-t.jsx</a></li>
411+
<li class="source-file"><a href="t/compile_error/141.maybeundefined-arraytype.jsx" data-path="t/compile_error/141.maybeundefined-arraytype.jsx">141.maybeundefined-arraytype.jsx</a></li>
407412

408413
</ul>
409414
</div><!--/.well -->

src/classdef.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ var ClassDefinition = exports.ClassDefinition = Class.extend({
511511
isConvertibleTo: function (classDef) {
512512
if (this == classDef)
513513
return true;
514+
if (classDef.className() == "Object")
515+
return true;
514516
if (this._extendType != null && this._extendType.getClassDef().isConvertibleTo(classDef))
515517
return true;
516518
for (var i = 0; i < this._implementTypes.length; ++i)

src/expression.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,10 @@ var ArrayLiteralExpression = exports.ArrayLiteralExpression = Expression.extend(
508508
} else {
509509
for (var i = 0; i < this._exprs.length; ++i) {
510510
var elementType = this._exprs[i].getType().resolveIfMayBeUndefined();
511-
if (! elementType.equals(Type.nullType)) {
511+
if (elementType.equals(Type.nullType)
512+
|| elementType.equals(Type.undefinedType)) {
513+
// skip
514+
} else {
512515
if (elementType.equals(Type.integerType))
513516
elementType = Type.numberType;
514517
var instantiatedClass = context.instantiateTemplate(context.errors, new TemplateInstantiationRequest(this._token, "Array", [ elementType ]));
@@ -524,7 +527,7 @@ var ArrayLiteralExpression = exports.ArrayLiteralExpression = Expression.extend(
524527
}
525528
}
526529
// check type of the elements
527-
var expectedType = this._type.getClassDef().getTypeArguments()[0];
530+
var expectedType = this._type.getClassDef().getTypeArguments()[0].toMayBeUndefinedType();
528531
for (var i = 0; i < this._exprs.length; ++i) {
529532
var elementType = this._exprs[i].getType();
530533
if (! elementType.isConvertibleTo(expectedType)) {

src/parser.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,9 @@ var Parser = exports.Parser = Class.extend({
836836
if (token.getValue() == "variant") {
837837
this._errors.push(new CompileError(token, "cannot use 'variant' as a class name"));
838838
return null;
839+
} else if (token.getValue() == "MayBeUndefined") {
840+
this._errors.push(new CompileError(token, "cannot use 'MayBeUndefined' as a class name"));
841+
return null;
839842
}
840843
var imprt = this.lookupImportAlias(token.getValue());
841844
if (imprt != null) {
@@ -1263,6 +1266,10 @@ var Parser = exports.Parser = Class.extend({
12631266
while (this._expectOpt("[") != null) {
12641267
if ((token = this._expect("]")) == null)
12651268
return false;
1269+
if (typeDecl instanceof MayBeUndefinedType) {
1270+
this._newError("MayBeUndefined.<T> cannot be an array, should be: T[]");
1271+
return null;
1272+
}
12661273
typeDecl = this._registerArrayTypeOf(token, typeDecl);
12671274
}
12681275
return typeDecl;
@@ -1352,10 +1359,10 @@ var Parser = exports.Parser = Class.extend({
13521359
if (token == null)
13531360
return null;
13541361
} while (token.getValue() == ",");
1355-
// disallow MayBeUndefined in template types (for the only existing types: MayBeUndefined, Array, Map)
1356-
if (types[0] instanceof MayBeUndefinedType) {
1357-
this._newError("type argument for class '" + qualifiedName.getToken().getValue() + "' cannot be a MayBeUndefined type");
1358-
return null;
1362+
// check
1363+
if (qualifiedName.getToken().getValue() == "Array" && types[0] instanceof MayBeUndefinedType) {
1364+
this._newError("cannot declare Array.<MayBeUndefined.<T>>, should be Array.<T>");
1365+
return false;
13591366
}
13601367
// request template instantiation (deferred)
13611368
this._templateInstantiationRequests.push(new TemplateInstantiationRequest(token, qualifiedName.getToken().getValue(), types));

src/type.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ var ParsedObjectType = exports.ParsedObjectType = ObjectType.extend({
418418
for (var i = 0; i < this._typeArguments.length; ++i) {
419419
var actualType = instantiationContext.typemap[this._typeArguments[i].toString()];
420420
typeArgs[i] = actualType != undefined ? actualType : this._typeArguments[i];
421+
// special handling for Array.<T> (T should not be MayBeUndefinedType)
422+
if (typeArgs[i] instanceof MayBeUndefinedType && this._qualifiedName.getToken().getValue() == "Array") {
423+
typeArgs[i] = typeArgs[i].getBaseType();
424+
}
421425
}
422426
instantiationContext.request.getInstantiationRequests().push(
423427
new TemplateInstantiationRequest(this._qualifiedName.getToken(), this._qualifiedName.getToken().getValue(), typeArgs));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Test {
2+
var n : MayBeUndefined.<MayBeUndefined.<number>> = 3;
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Test {
2+
static function run() : void {
3+
var a = [] : Array.<MayBeUndefined.<number>>;
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Test {
2+
static function run() : void {
3+
var a = [] : MayBeUndefined.<number> [];
4+
}
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*EXPECTED
2+
null
3+
null
4+
*/
5+
interface I {
6+
}
7+
mixin M {
8+
}
9+
class Test {
10+
static function run() : void {
11+
var i : I = null;
12+
var o : Object = i;
13+
log o;
14+
var m : M = null;
15+
o = m;
16+
log o;
17+
}
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*EXPECTED
2+
1,2,
3+
,2,
4+
1,2,
5+
,2,
6+
1,2,
7+
,2,
8+
*/
9+
class Test {
10+
static function run() : void {
11+
var a = [ 1, 2, undefined ];
12+
log a.join(",");
13+
a[0] = undefined;
14+
log a.join(",");
15+
a = [ 1, 2, undefined ] : number[];
16+
log a.join(",");
17+
a[0] = undefined;
18+
log a.join(",");
19+
a = [ 1, 2, undefined ] : Array.<number>;
20+
log a.join(",");
21+
a[0] = undefined;
22+
log a.join(",");
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*EXPECTED
2+
1,2,3
3+
*/
4+
class K.<T> {
5+
static function f() : T[] {
6+
return [ 1, 2, 3 ];
7+
}
8+
}
9+
class Test {
10+
static function run() : void {
11+
var a : Array.<number> = K.<MayBeUndefined.<number>>.f();
12+
log a.join(",");
13+
}
14+
}

tree.generated.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@
217217
"079.uninitialized-in-switch.jsx" : "/try/t/compile_error/079.uninitialized-in-switch.jsx",
218218
"031.interface-loop.jsx" : "/try/t/compile_error/031.interface-loop.jsx",
219219
"112.import-all-invalid-wildcard.jsx" : "/try/t/compile_error/112.import-all-invalid-wildcard.jsx",
220+
"140.array-maybeundefined-t.jsx" : "/try/t/compile_error/140.array-maybeundefined-t.jsx",
220221
"100.as-noconvert.jsx" : "/try/t/compile_error/100.as-noconvert.jsx",
221222
"036.implement-mixin-twice.jsx" : "/try/t/compile_error/036.implement-mixin-twice.jsx",
222223
"099.type-propagation-of-undeclared-func.jsx" : "/try/t/compile_error/099.type-propagation-of-undeclared-func.jsx",
@@ -299,12 +300,14 @@
299300
"089.unreachable-after-return.jsx" : "/try/t/compile_error/089.unreachable-after-return.jsx",
300301
"080.uninitialized-in-switch-wo-default.jsx" : "/try/t/compile_error/080.uninitialized-in-switch-wo-default.jsx",
301302
"113.readonly.jsx" : "/try/t/compile_error/113.readonly.jsx",
303+
"139.nested-maybeundefined.jsx" : "/try/t/compile_error/139.nested-maybeundefined.jsx",
302304
"034.interface-with-body.jsx" : "/try/t/compile_error/034.interface-with-body.jsx",
303305
"087.unreachable-after-break-with-label.jsx" : "/try/t/compile_error/087.unreachable-after-break-with-label.jsx",
304306
"123.as-against-func-var.jsx" : "/try/t/compile_error/123.as-against-func-var.jsx",
305307
"133.invalid-expr-in-if-cond.jsx" : "/try/t/compile_error/133.invalid-expr-in-if-cond.jsx",
306308
"076.bitnot-nonnumber.jsx" : "/try/t/compile_error/076.bitnot-nonnumber.jsx",
307309
"114.func-arg-is-overloaded-func.jsx" : "/try/t/compile_error/114.func-arg-is-overloaded-func.jsx",
310+
"141.maybeundefined-arraytype.jsx" : "/try/t/compile_error/141.maybeundefined-arraytype.jsx",
308311
"122.as-against-overload-resolution-error.jsx" : "/try/t/compile_error/122.as-against-overload-resolution-error.jsx",
309312
"130.inherited-abstract-class.jsx" : "/try/t/compile_error/130.inherited-abstract-class.jsx",
310313
"118.redundant-maybeundefined.jsx" : "/try/t/compile_error/118.redundant-maybeundefined.jsx",
@@ -369,6 +372,7 @@
369372
"148.null-in-cond-expr.jsx" : "/try/t/run/148.null-in-cond-expr.jsx",
370373
"169.typeof-maybeundefined.jsx" : "/try/t/run/169.typeof-maybeundefined.jsx",
371374
"142.static-closure.jsx" : "/try/t/run/142.static-closure.jsx",
375+
"173.interface-or-mixin-as-object.jsx" : "/try/t/run/173.interface-or-mixin-as-object.jsx",
372376
"079.logical-op.jsx" : "/try/t/run/079.logical-op.jsx",
373377
"037.as-on-maybe.jsx" : "/try/t/run/037.as-on-maybe.jsx",
374378
"141.for-with-multiple-vars.jsx" : "/try/t/run/141.for-with-multiple-vars.jsx",
@@ -449,6 +453,7 @@
449453
"168.local-function-declaration.jsx" : "/try/t/run/168.local-function-declaration.jsx",
450454
"136.maybeundefined-as-obj.jsx" : "/try/t/run/136.maybeundefined-as-obj.jsx",
451455
"033.many-class.jsx" : "/try/t/run/033.many-class.jsx",
456+
"175.T-of-ArrayT-should-never-be-maybeundef.jsx" : "/try/t/run/175.T-of-ArrayT-should-never-be-maybeundef.jsx",
452457
"127.base-prop-for-maybeundefined.jsx" : "/try/t/run/127.base-prop-for-maybeundefined.jsx",
453458
"137.same-pred-op-with-parens.jsx" : "/try/t/run/137.same-pred-op-with-parens.jsx",
454459
"031.overload.jsx" : "/try/t/run/031.overload.jsx",
@@ -485,8 +490,8 @@
485490
"110.as-precedence.jsx" : "/try/t/run/110.as-precedence.jsx",
486491
"042.Boolean.jsx" : "/try/t/run/042.Boolean.jsx",
487492
"138.json-complex.jsx" : "/try/t/run/138.json-complex.jsx",
488-
"130.math-abs.jsx" : "/try/t/run/130.math-abs.jsx",
489493
"080.return-void.jsx" : "/try/t/run/080.return-void.jsx",
494+
"130.math-abs.jsx" : "/try/t/run/130.math-abs.jsx",
490495
"010.condop.jsx" : "/try/t/run/010.condop.jsx",
491496
"097.json.jsx" : "/try/t/run/097.json.jsx",
492497
"117.avoid-import-conflict-using-as" : {
@@ -499,7 +504,6 @@
499504
"157.deduct-closure-type-in-new.jsx" : "/try/t/run/157.deduct-closure-type-in-new.jsx",
500505
"140.basic-template.jsx" : "/try/t/run/140.basic-template.jsx",
501506
"092.call-func-in-array.jsx" : "/try/t/run/092.call-func-in-array.jsx",
502-
"032.nested-maybeundefined.jsx" : "/try/t/run/032.nested-maybeundefined.jsx",
503507
"062.import-as" : {
504508
"foo.jsx" : "/try/t/run/062.import-as/foo.jsx"
505509
},
@@ -521,6 +525,7 @@
521525
"100.for-in-map.jsx" : "/try/t/run/100.for-in-map.jsx",
522526
"123.tostring-as-property.jsx" : "/try/t/run/123.tostring-as-property.jsx",
523527
"105.in.jsx" : "/try/t/run/105.in.jsx",
528+
"174.undefined-in-array-literal.jsx" : "/try/t/run/174.undefined-in-array-literal.jsx",
524529
"024.date.jsx" : "/try/t/run/024.date.jsx",
525530
"055.downcast.jsx" : "/try/t/run/055.downcast.jsx",
526531
"146.assign-to-property-of-variant.jsx" : "/try/t/run/146.assign-to-property-of-variant.jsx",

0 commit comments

Comments
 (0)