Some fumbling with isSubTypeOf and add test for final.

This commit is contained in:
Juraj Kirchheim
2019-03-03 17:13:04 +01:00
parent 296cc6c861
commit 53868cc6f3
5 changed files with 28 additions and 10 deletions

View File

@@ -1 +1,4 @@
{"version":"3.4.7","resolveLibs":"scoped"} {
"version": "4.0.0-rc.1",
"resolveLibs": "scoped"
}

View File

@@ -1,5 +0,0 @@
{
"haxe.displayConfigurations": [
["tests.hxml"]
]
}

6
dev.hxml Normal file
View File

@@ -0,0 +1,6 @@
tests.hxml
-lib travix
-lib tink_macro
-lib hx3compat
-js whatever.js
--no-output

View File

@@ -126,7 +126,8 @@ class Types {
static public function isSubTypeOf(t:Type, of:Type, ?pos) static public function isSubTypeOf(t:Type, of:Type, ?pos)
return return
ECheckType(ECheckType(macro null, toComplex(t)).at(pos), toComplex(of)).at(pos).typeof(); if (Context.unify(t, of)) ECheckType(ECheckType(macro null, toComplex(t)).at(pos), toComplex(of)).at(pos).typeof();
else Failure(new Error(t.toString() + ' should be ' + of.toString(), pos.sanitize()));
static public function isDynamic(t:Type) static public function isDynamic(t:Type)
return switch reduce(t) { return switch reduce(t) {

View File

@@ -1,5 +1,6 @@
package ; package ;
#if macro
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.macro.Context; import haxe.macro.Context;
@@ -20,6 +21,7 @@ class Types extends Base {
assertFalse(o.isSuccess()); assertFalse(o.isSuccess());
function testIs() { function testIs() {
assertSuccess(resolve('Int').isSubTypeOf(resolve('Float'))); assertSuccess(resolve('Int').isSubTypeOf(resolve('Float')));
assertFailure(resolve('Float').isSubTypeOf(resolve('Int'))); assertFailure(resolve('Float').isSubTypeOf(resolve('Int')));
} }
@@ -41,10 +43,20 @@ class Types extends Base {
var bool = type(macro : Bool); var bool = type(macro : Bool);
assertTrue(blank().isSubTypeOf(bool).isSuccess()); assertTrue(blank().isSubTypeOf(bool).isSuccess());
assertTrue(bool.isSubTypeOf(blank()).isSuccess()); assertTrue(bool.isSubTypeOf(blank()).isSuccess());
MacroApi.pos().makeBlankType().toString();
} }
#if haxe4
function testFinal() {
var t = macro : {
final foo:Int;
};
switch t.toType().sure() {
case TAnonymous(_.get().fields => [f]): assertTrue(f.isFinal);
default:
}
}
#end
function testExpr() { function testExpr() {
assertEquals('VarChar<255>', (macro : VarChar<255>).toType().sure().toComplex().toString()); assertEquals('VarChar<255>', (macro : VarChar<255>).toType().sure().toComplex().toString());
} }
@@ -53,4 +65,5 @@ class Types extends Base {
assertEquals('String', Context.getType('String').toComplex().toString()); assertEquals('String', Context.getType('String').toComplex().toString());
assertEquals('tink.CoreApi.Noise', Context.getType('tink.CoreApi.Noise').toComplex().toString()); assertEquals('tink.CoreApi.Noise', Context.getType('tink.CoreApi.Noise').toComplex().toString());
} }
} }
#end