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)
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)
return switch reduce(t) {

View File

@@ -1,5 +1,6 @@
package ;
#if macro
import haxe.macro.Expr;
import haxe.macro.Context;
@@ -20,6 +21,7 @@ class Types extends Base {
assertFalse(o.isSuccess());
function testIs() {
assertSuccess(resolve('Int').isSubTypeOf(resolve('Float')));
assertFailure(resolve('Float').isSubTypeOf(resolve('Int')));
}
@@ -41,10 +43,20 @@ class Types extends Base {
var bool = type(macro : Bool);
assertTrue(blank().isSubTypeOf(bool).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() {
assertEquals('VarChar<255>', (macro : VarChar<255>).toType().sure().toComplex().toString());
}
@@ -54,3 +66,4 @@ class Types extends Base {
assertEquals('tink.CoreApi.Noise', Context.getType('tink.CoreApi.Noise').toComplex().toString());
}
}
#end