Some fumbling with isSubTypeOf and add test for final.
This commit is contained in:
5
.haxerc
5
.haxerc
@@ -1 +1,4 @@
|
||||
{"version":"3.4.7","resolveLibs":"scoped"}
|
||||
{
|
||||
"version": "4.0.0-rc.1",
|
||||
"resolveLibs": "scoped"
|
||||
}
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"haxe.displayConfigurations": [
|
||||
["tests.hxml"]
|
||||
]
|
||||
}
|
6
dev.hxml
Normal file
6
dev.hxml
Normal file
@@ -0,0 +1,6 @@
|
||||
tests.hxml
|
||||
-lib travix
|
||||
-lib tink_macro
|
||||
-lib hx3compat
|
||||
-js whatever.js
|
||||
--no-output
|
@@ -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) {
|
||||
|
@@ -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
|
Reference in New Issue
Block a user