Compare commits
12 Commits
isAbstract
...
build-cach
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc9f7460c2 | ||
|
|
043df0f47d | ||
|
|
7e2dfad607 | ||
|
|
94d02c91a8 | ||
|
|
99a1fc3fa6 | ||
|
|
a383f7692b | ||
|
|
5e5781e8bc | ||
|
|
63ce1853f5 | ||
|
|
f3ddaa6496 | ||
|
|
f46e49ce66 | ||
|
|
007c73d58e | ||
|
|
8c5903833c |
@@ -9,8 +9,8 @@
|
|||||||
"contributors": [
|
"contributors": [
|
||||||
"back2dos"
|
"back2dos"
|
||||||
],
|
],
|
||||||
"version": "0.21.1",
|
"version": "0.22.0",
|
||||||
"releasenote": "Fix issue with build field retrieval.",
|
"releasenote": "Support Haxe 4.2",
|
||||||
"tags": [
|
"tags": [
|
||||||
"tink",
|
"tink",
|
||||||
"macro",
|
"macro",
|
||||||
|
|||||||
@@ -17,18 +17,18 @@ typedef BuildContextN = {
|
|||||||
|
|
||||||
|
|
||||||
typedef BuildContext = {
|
typedef BuildContext = {
|
||||||
pos:Position,
|
var pos(default, never):Position;
|
||||||
type:Type,
|
var type(default, never):Type;
|
||||||
usings:Array<TypePath>,
|
var usings(default, never):Array<TypePath>;
|
||||||
name:String,
|
var name(default, never):String;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BuildContext2 = {>BuildContext,
|
typedef BuildContext2 = {>BuildContext,
|
||||||
type2:Type,
|
var type2(default, never):Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BuildContext3 = {>BuildContext2,
|
typedef BuildContext3 = {>BuildContext2,
|
||||||
type3:Type,
|
var type3(default, never):Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
class BuildCache {
|
class BuildCache {
|
||||||
@@ -36,29 +36,20 @@ class BuildCache {
|
|||||||
@:persistent static var cache = new Map();
|
@:persistent static var cache = new Map();
|
||||||
|
|
||||||
static public function getType3(name, ?types, ?pos:Position, build:BuildContext3->TypeDefinition, ?normalizer:Type->Type) {
|
static public function getType3(name, ?types, ?pos:Position, build:BuildContext3->TypeDefinition, ?normalizer:Type->Type) {
|
||||||
if (types == null)
|
return _getTypeN(name, 3, switch types {
|
||||||
switch Context.getLocalType() {
|
case null: null;
|
||||||
case TInst(_.toString() == name => true, [t1, t2, t3]):
|
case v: [types.t1, types.t2, types.t3];
|
||||||
types = { t1: t1, t2: t2, t3: t3 };
|
}, pos, ctx -> build({
|
||||||
default:
|
|
||||||
throw 'assert';
|
|
||||||
}
|
|
||||||
|
|
||||||
var t1 = types.t1.toComplexType(),
|
|
||||||
t2 = types.t2.toComplexType(),
|
|
||||||
t3 = types.t2.toComplexType();
|
|
||||||
|
|
||||||
return getType(name, (macro : { t1: $t1, t2: $t2, t3: $t3 } ).toType(), pos, function (ctx) return build({
|
|
||||||
type: types.t1,
|
|
||||||
type2: types.t2,
|
|
||||||
type3: types.t3,
|
|
||||||
pos: ctx.pos,
|
pos: ctx.pos,
|
||||||
name: ctx.name,
|
type: ctx.types[0],
|
||||||
usings: ctx.usings
|
type2: ctx.types[1],
|
||||||
|
type3: ctx.types[2],
|
||||||
|
usings: ctx.usings,
|
||||||
|
name: ctx.name
|
||||||
}), normalizer);
|
}), normalizer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function getTypeN(name, ?types, ?pos:Position, build:BuildContextN->TypeDefinition, ?normalizer:Type->Type) {
|
static function _getTypeN(name, length, ?types, ?pos:Position, build:BuildContextN->TypeDefinition, ?normalizer:Type->Type) {
|
||||||
|
|
||||||
if (pos == null)
|
if (pos == null)
|
||||||
pos = Context.currentPos();
|
pos = Context.currentPos();
|
||||||
@@ -67,50 +58,37 @@ class BuildCache {
|
|||||||
switch Context.getLocalType() {
|
switch Context.getLocalType() {
|
||||||
case TInst(_.toString() == name => true, params):
|
case TInst(_.toString() == name => true, params):
|
||||||
types = params;
|
types = params;
|
||||||
default:
|
case t:
|
||||||
throw 'assert';
|
pos.error('expected $name but found ${t.toString()}');
|
||||||
}
|
}
|
||||||
|
|
||||||
var compound = ComplexType.TAnonymous([for (i in 0...types.length) {
|
if (length != -1 && types.length != length)
|
||||||
name: 't$i',
|
pos.error('expected $length parameter${if (length == 1) '' else 's'}');
|
||||||
pos: pos,
|
|
||||||
kind: FVar(switch types[i] {
|
|
||||||
case TInst(_.get().kind => KExpr(e), _):
|
|
||||||
TPath('tink.macro.ConstParam'.asTypePath([TPExpr(e)]));
|
|
||||||
case t: t.toComplex();
|
|
||||||
}),
|
|
||||||
}]).toType();
|
|
||||||
|
|
||||||
return getType(name, compound, pos, function (ctx) return build({
|
var forName =
|
||||||
types: types,
|
switch cache[name] {
|
||||||
pos: ctx.pos,
|
case null: cache[name] = new Group(name);
|
||||||
name: ctx.name,
|
case v: v;
|
||||||
usings: ctx.usings
|
|
||||||
}), normalizer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static public function getType2(name, ?types, ?pos:Position, build:BuildContext2->TypeDefinition, ?normalizer:Type->Type) {
|
|
||||||
if (types == null)
|
|
||||||
switch Context.getLocalType() {
|
|
||||||
case TInst(_.toString() == name => true, [t1, t2]):
|
|
||||||
types = { t1: t1, t2: t2 };
|
|
||||||
default:
|
|
||||||
throw 'assert';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var t1 = types.t1.toComplexType(),
|
var ret = forName.get(types, pos.sanitize(), build, normalizer);
|
||||||
t2 = types.t2.toComplexType();
|
ret.getFields();// workaround for https://github.com/HaxeFoundation/haxe/issues/7905
|
||||||
|
return ret;
|
||||||
return getType(name, (macro : { t1: $t1, t2: $t2 } ).toType(), pos, function (ctx) return build({
|
|
||||||
type: types.t1,
|
|
||||||
type2: types.t2,
|
|
||||||
pos: ctx.pos,
|
|
||||||
name: ctx.name,
|
|
||||||
usings: ctx.usings
|
|
||||||
}), normalizer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function getParams(name:String, ?pos:Position)
|
static public function getType2(name, ?types, ?pos:Position, build:BuildContext2->TypeDefinition, ?normalizer:Type->Type)
|
||||||
|
return _getTypeN(name, 2, switch types {
|
||||||
|
case null: null;
|
||||||
|
case v: [types.t1, types.t2];
|
||||||
|
}, pos, ctx -> build({
|
||||||
|
pos: ctx.pos,
|
||||||
|
type: ctx.types[0],
|
||||||
|
type2: ctx.types[1],
|
||||||
|
usings: ctx.usings,
|
||||||
|
name: ctx.name
|
||||||
|
}), normalizer);
|
||||||
|
|
||||||
|
static public function getParams(name:String, ?pos:Position, ?count:Int)
|
||||||
return
|
return
|
||||||
switch Context.getLocalType() {
|
switch Context.getLocalType() {
|
||||||
case TInst(_.toString() == name => true, v):
|
case TInst(_.toString() == name => true, v):
|
||||||
@@ -131,70 +109,50 @@ class BuildCache {
|
|||||||
});
|
});
|
||||||
|
|
||||||
static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition, ?normalizer:Type->Type) {
|
static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition, ?normalizer:Type->Type) {
|
||||||
|
return _getTypeN(name, 1, switch type {
|
||||||
if (type == null)
|
case null: null;
|
||||||
type = getParam(name, pos).sure();
|
case v: [v];
|
||||||
|
}, pos, ctx -> build({
|
||||||
var forName =
|
pos: ctx.pos,
|
||||||
switch cache[name] {
|
type: ctx.types[0],
|
||||||
case null: cache[name] = new Group(name, normalizer);
|
usings: ctx.usings,
|
||||||
case v: v;
|
name: ctx.name
|
||||||
}
|
}), normalizer);
|
||||||
|
|
||||||
var ret = forName.get(type, pos.sanitize(), build);
|
|
||||||
ret.getFields();// workaround for https://github.com/HaxeFoundation/haxe/issues/7905
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private typedef Entry = {
|
private class Group {//TODO: this is somewhat obsolete
|
||||||
name:String,
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Group {
|
|
||||||
|
|
||||||
var name:String;
|
var name:String;
|
||||||
var counter = 0;
|
|
||||||
var entries:TypeMap<Entry>;
|
|
||||||
|
|
||||||
public function new(name, ?normalizer) {
|
public function new(name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.entries = new TypeMap(normalizer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(type:Type, pos:Position, build:BuildContext->TypeDefinition):Type {
|
public function get(types:Array<Type>, pos:Position, build:BuildContextN->TypeDefinition, ?normalizer):Type {
|
||||||
|
|
||||||
function make(path:String) {
|
types = types.map(switch normalizer {
|
||||||
var usings = [];
|
case null: function (t) return Context.follow(t);
|
||||||
var def = build({
|
case f: f;
|
||||||
pos: pos,
|
});
|
||||||
type: type,
|
|
||||||
usings: usings,
|
|
||||||
name: path.split('.').pop()
|
|
||||||
});
|
|
||||||
|
|
||||||
entries.set(type, { name: path } );
|
var retName = name + '_' + Context.signature(Sisyphus.exactParams(types));
|
||||||
Context.defineModule(path, [def], usings);
|
|
||||||
return Context.getType(path);
|
return switch retName.definedType() {
|
||||||
|
case Some(v): v;
|
||||||
|
case None:
|
||||||
|
var usings = [];
|
||||||
|
var path = name.split('.');
|
||||||
|
|
||||||
|
var ret = build({
|
||||||
|
pos: pos,
|
||||||
|
types: types,
|
||||||
|
usings: usings,
|
||||||
|
name: retName.split('.').pop(),
|
||||||
|
});
|
||||||
|
|
||||||
|
Context.defineModule(retName, [ret], usings);
|
||||||
|
Context.getType(retName);
|
||||||
}
|
}
|
||||||
|
|
||||||
function doMake()
|
|
||||||
while (true)
|
|
||||||
switch '$name${counter++}' {
|
|
||||||
case _.definedType() => Some(_):
|
|
||||||
case v:
|
|
||||||
return make(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
switch entries.get(type) {
|
|
||||||
case null:
|
|
||||||
doMake();
|
|
||||||
case v:
|
|
||||||
switch v.name.definedType() {
|
|
||||||
case Some(v): v;
|
|
||||||
default: doMake();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,8 @@ package tink.macro;
|
|||||||
|
|
||||||
import haxe.macro.Expr;
|
import haxe.macro.Expr;
|
||||||
import haxe.macro.Type;
|
import haxe.macro.Type;
|
||||||
|
using haxe.macro.Tools;
|
||||||
|
using tink.MacroApi;
|
||||||
|
|
||||||
class Sisyphus {
|
class Sisyphus {
|
||||||
|
|
||||||
@@ -61,8 +63,7 @@ class Sisyphus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function toComplexType(type : Null<Type>) : Null<ComplexType> return {
|
||||||
public static function toComplexType(type : Null<Type>) : Null<ComplexType> return {
|
|
||||||
inline function direct()
|
inline function direct()
|
||||||
return Types.toComplex(type, { direct: true });
|
return Types.toComplex(type, { direct: true });
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -136,4 +137,91 @@ class Sisyphus {
|
|||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function exactBase<T:BaseType>(r:Ref<T>, params:Array<Type>) {
|
||||||
|
var t = r.get();
|
||||||
|
var isMain = !t.isPrivate && switch t.pack {
|
||||||
|
case []: t.module == t.name || t.module == 'StdTypes';
|
||||||
|
default: StringTools.endsWith(t.module, '.${t.name}');
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
if (isMain) t.pack.concat([t.name]).join('.')
|
||||||
|
else t.module + '.' + t.name
|
||||||
|
) + exactParams(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline function isFinal(c:ClassField)
|
||||||
|
return #if haxe4 c.isFinal #else false #end;
|
||||||
|
|
||||||
|
static function exactAnonField(c:ClassField) {
|
||||||
|
var kw =
|
||||||
|
switch c.kind {
|
||||||
|
case FMethod(_): 'function';
|
||||||
|
case FVar(_):
|
||||||
|
if (isFinal(c)) 'final' else 'var';
|
||||||
|
}
|
||||||
|
|
||||||
|
return [for (m in c.meta.get()) m.toString() + ' '].join('') + '$kw ${c.name}' + (switch c.kind {
|
||||||
|
case FVar(read, write):
|
||||||
|
(
|
||||||
|
if (isFinal(c) || (read == AccNormal && write == AccNormal)) ''
|
||||||
|
else '(${read.accessToName()}, ${read.accessToName(false)})'
|
||||||
|
) + ':' + c.type.toExactString();
|
||||||
|
case FMethod(_):
|
||||||
|
switch haxe.macro.Context.follow(c.type) {
|
||||||
|
case TFun(arg, ret): exactSig(arg, ret, ':');
|
||||||
|
default: throw 'assert';
|
||||||
|
}
|
||||||
|
}) + ';';
|
||||||
|
}
|
||||||
|
|
||||||
|
static function exactSig(args:Array<{name:String, opt:Bool, t:Type}>, ret:Type, sep:String)
|
||||||
|
return '(${[for (a in args) (if (a.opt) '?' else '') + a.name + ':' + toExactString(a.t)].join(', ')})$sep${toExactString(ret)}';
|
||||||
|
|
||||||
|
static public function exactParams(params:Array<Type>)
|
||||||
|
return switch params {
|
||||||
|
case []: '';
|
||||||
|
case params:
|
||||||
|
'<${params.map(toExactString).join(', ')}>';
|
||||||
|
}
|
||||||
|
static public function toExactString(t:Type)
|
||||||
|
return switch t {
|
||||||
|
case TMono(t): t.toString();
|
||||||
|
case TEnum(r, params): exactBase(r, params);
|
||||||
|
case TInst(r, params): exactBase(r, params);
|
||||||
|
case TType(r, params): exactBase(r, params);
|
||||||
|
case TAbstract(r, params): exactBase(r, params);
|
||||||
|
case TFun(args, ret): exactSig(args, ret, '->');
|
||||||
|
case TAnonymous(a): '{ ${[for (f in a.get().fields) exactAnonField(f)].join(' ')} }';
|
||||||
|
case TDynamic(null): 'Dynamic';
|
||||||
|
case TDynamic(t): 'Dynamic<${toExactString(t)}>';
|
||||||
|
case TLazy(f): toExactString(f());
|
||||||
|
}
|
||||||
|
|
||||||
|
static function eager(t:Type)
|
||||||
|
return switch t {
|
||||||
|
case TLazy(f): eager(f());
|
||||||
|
default: t;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function compare(t1:Type, t2:Type, ?follow:Bool = true) {
|
||||||
|
if (follow) {
|
||||||
|
t1 = t1.reduce();
|
||||||
|
t2 = t2.reduce();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
t1 = eager(t1);
|
||||||
|
t2 = eager(t2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return switch t1.getIndex() - t2.getIndex() {
|
||||||
|
case 0:
|
||||||
|
switch Reflect.compare(t1.toString(), t2.toString()) {
|
||||||
|
case 0: Reflect.compare(t1.toExactString(), t2.toExactString());
|
||||||
|
case v: v;
|
||||||
|
}
|
||||||
|
case v: v;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ using haxe.macro.Tools;
|
|||||||
using tink.MacroApi;
|
using tink.MacroApi;
|
||||||
using tink.CoreApi;
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
import haxe.macro.Type.Ref;
|
||||||
|
|
||||||
class Types {
|
class Types {
|
||||||
|
|
||||||
static public function definedType(typeName:String)
|
static public function definedType(typeName:String):Option<Type>
|
||||||
return
|
return
|
||||||
try {
|
try {
|
||||||
Some(Context.getType(typeName));
|
Some(Context.getType(typeName));
|
||||||
@@ -208,7 +210,22 @@ class Types {
|
|||||||
default: Failure('type "$t" has no position');
|
default: Failure('type "$t" has no position');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function deduceCommonType(types:Array<Type>):Outcome<Type, Error> {
|
||||||
|
var exprs = types.map(function(t) {
|
||||||
|
var ct = t.toComplex();
|
||||||
|
return macro (null:$ct);
|
||||||
|
});
|
||||||
|
|
||||||
|
return switch (macro $a{exprs}).typeof() {
|
||||||
|
case Success(TInst(_, [v])): Success(v);
|
||||||
|
case Success(_): throw 'unreachable';
|
||||||
|
case Failure(e): Failure(new Error('Unable to deduce common type among $types'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// like haxe.macro.TypeTools.toString, but not lossy
|
||||||
|
static public function toExactString(t:Type)
|
||||||
|
return Sisyphus.toExactString(t);
|
||||||
|
|
||||||
static public function toString(t:ComplexType)
|
static public function toString(t:ComplexType)
|
||||||
return new Printer().printComplexType(t);
|
return new Printer().printComplexType(t);
|
||||||
@@ -296,6 +313,9 @@ class Types {
|
|||||||
|
|
||||||
if (types.length == 1) return Success(types[1]);
|
if (types.length == 1) return Success(types[1]);
|
||||||
|
|
||||||
|
#if haxe4
|
||||||
|
return Success(TIntersection(types));
|
||||||
|
#end
|
||||||
var paths = [],
|
var paths = [],
|
||||||
fields = [];
|
fields = [];
|
||||||
|
|
||||||
@@ -337,18 +357,8 @@ class Types {
|
|||||||
throw 'assert';
|
throw 'assert';
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function compare(t1:Type, t2:Type, ?follow:Bool = true) {
|
static public function compare(t1:Type, t2:Type, ?follow:Bool = true)
|
||||||
if (follow) {
|
return Sisyphus.compare(t1, t2, follow);
|
||||||
t1 = t1.reduce();
|
|
||||||
t2 = t2.reduce();
|
|
||||||
}
|
|
||||||
|
|
||||||
return switch t1.getIndex() - t2.getIndex() {
|
|
||||||
case 0:
|
|
||||||
Reflect.compare(t1.toString(), t2.toString());//much to my surprise, this actually seems to work (at least with 3.4)
|
|
||||||
case v: v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static var SUGGESTIONS = ~/ \(Suggestions?: .*\)$/;
|
static var SUGGESTIONS = ~/ \(Suggestions?: .*\)$/;
|
||||||
|
|
||||||
|
|||||||
8
tests/Dummy.hx
Normal file
8
tests/Dummy.hx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
class Dummy {
|
||||||
|
public function new() {}
|
||||||
|
static public var p(default, never) = new Private();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Private {
|
||||||
|
public function new() {}
|
||||||
|
}
|
||||||
21
tests/ExactStrings.hx
Normal file
21
tests/ExactStrings.hx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import haxe.macro.Context.typeof;
|
||||||
|
using tink.MacroApi;
|
||||||
|
|
||||||
|
class ExactStrings extends Base {
|
||||||
|
function test() {
|
||||||
|
function expect(s:String, e, ?pos)
|
||||||
|
assertEquals(s, typeof(e).toExactString(), pos);
|
||||||
|
|
||||||
|
expect('Dummy', macro new Dummy());
|
||||||
|
expect('nested.Dummy', macro new nested.Dummy());
|
||||||
|
expect('Dummy.Private', macro Dummy.p);
|
||||||
|
expect('nested.Dummy.Private', macro nested.Dummy.p);
|
||||||
|
expect('{ @foo var x:Int; }', macro (null:{@foo var x:Int;}));
|
||||||
|
expect('{ @foo @bar var x:Int; }', macro (null:{@foo @bar var x:Int;}));
|
||||||
|
expect('{ @bar @foo var x:Int; }', macro (null:{@bar @foo var x:Int;}));// not 100% sure this is always the best choice, but let's roll with it
|
||||||
|
expect('{ @bar var x:Int; }', macro (null:{@bar var x:Int;}));
|
||||||
|
expect('{ var x:Int; var y:Int; }', macro (null:{x:Int,y:Int}));
|
||||||
|
expect('{ var x:Int; var y:Int; }', macro (null:{y:Int,x:Int}));
|
||||||
|
expect('{ function foo(x:Int, ?y:Int):Void; }', macro (null:{ function foo(x:Int, ?y:Int):Void; }));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package ;
|
package ;
|
||||||
|
|
||||||
import haxe.unit.*;
|
import haxe.unit.*;
|
||||||
|
#if macro
|
||||||
|
using haxe.macro.Tools;
|
||||||
|
#end
|
||||||
|
|
||||||
class Run {
|
class Run {
|
||||||
#if !macro
|
#if !macro
|
||||||
@@ -14,6 +17,7 @@ class Run {
|
|||||||
new TypeMapTest(),
|
new TypeMapTest(),
|
||||||
new Functions(),
|
new Functions(),
|
||||||
new Misc(),
|
new Misc(),
|
||||||
|
new ExactStrings(),
|
||||||
];
|
];
|
||||||
#end
|
#end
|
||||||
macro static function test() {
|
macro static function test() {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ class TypeMapTest extends TestCase {
|
|||||||
var t = new TypeMap();
|
var t = new TypeMap();
|
||||||
var t1 = (macro [{ foo: [{ bar: '5' }]}]).typeof().sure();
|
var t1 = (macro [{ foo: [{ bar: '5' }]}]).typeof().sure();
|
||||||
var t2 = (macro [{ foo: [{ bar: 5 }]}]).typeof().sure();
|
var t2 = (macro [{ foo: [{ bar: 5 }]}]).typeof().sure();
|
||||||
|
var t3 = (macro [{ foo: [{ bar: 5 }]}]).typeof().sure();
|
||||||
|
var t4 = (macro [{ foo: [({ bar: 5 }:{ @foo var bar:Int; })]}]).typeof().sure();
|
||||||
|
|
||||||
t.set(t1, 0);
|
t.set(t1, 0);
|
||||||
assertEquals(Lambda.count(t), 1);
|
assertEquals(Lambda.count(t), 1);
|
||||||
@@ -19,7 +21,10 @@ class TypeMapTest extends TestCase {
|
|||||||
t.set(t1, 2);
|
t.set(t1, 2);
|
||||||
assertEquals(Lambda.count(t), 2);
|
assertEquals(Lambda.count(t), 2);
|
||||||
t.set(t2, 3);
|
t.set(t2, 3);
|
||||||
|
t.set(t3, 3);
|
||||||
assertEquals(Lambda.count(t), 2);
|
assertEquals(Lambda.count(t), 2);
|
||||||
|
t.set(t4, 4);
|
||||||
|
assertEquals(Lambda.count(t), 3);
|
||||||
|
|
||||||
assertEquals(t.get(t1), 2);
|
assertEquals(t.get(t1), 2);
|
||||||
assertEquals(t.get(t2), 3);
|
assertEquals(t.get(t2), 3);
|
||||||
|
|||||||
@@ -10,36 +10,35 @@ using tink.MacroApi;
|
|||||||
class Types extends Base {
|
class Types extends Base {
|
||||||
function type(c:ComplexType)
|
function type(c:ComplexType)
|
||||||
return c.toType().sure();
|
return c.toType().sure();
|
||||||
|
|
||||||
function resolve(type:String)
|
function resolve(type:String)
|
||||||
return Context.getType(type);
|
return Context.getType(type);
|
||||||
|
|
||||||
inline function assertSuccess<S, F>(o:Outcome<S, F>)
|
inline function assertSuccess<S, F>(o:Outcome<S, F>)
|
||||||
assertTrue(o.isSuccess());
|
assertTrue(o.isSuccess());
|
||||||
|
|
||||||
inline function assertFailure<S, F>(o:Outcome<S, F>)
|
inline function assertFailure<S, F>(o:Outcome<S, F>)
|
||||||
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')));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testFields() {
|
function testFields() {
|
||||||
var expected = type(macro : Void -> Iterator<Arrayish>),
|
var expected = type(macro : Void -> Iterator<Arrayish>),
|
||||||
iterator = type(macro : haxe.ds.StringMap<Arrayish>).getFields(true).sure().filter(function (c) return c.name == 'iterator')[0];
|
iterator = type(macro : haxe.ds.StringMap<Arrayish>).getFields(true).sure().filter(function (c) return c.name == 'iterator')[0];
|
||||||
|
|
||||||
assertSuccess(iterator.type.isSubTypeOf(expected));
|
assertSuccess(iterator.type.isSubTypeOf(expected));
|
||||||
assertSuccess(expected.isSubTypeOf(iterator.type));
|
assertSuccess(expected.isSubTypeOf(iterator.type));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testConvert() {
|
function testConvert() {
|
||||||
assertSuccess((macro : Int).toType());
|
assertSuccess((macro : Int).toType());
|
||||||
assertFailure((macro : Tni).toType());
|
assertFailure((macro : Tni).toType());
|
||||||
function blank()
|
function blank()
|
||||||
return type(MacroApi.pos().makeBlankType());
|
return type(MacroApi.pos().makeBlankType());
|
||||||
|
|
||||||
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());
|
||||||
@@ -65,5 +64,20 @@ 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testDeduceCommonType() {
|
||||||
|
function ct2t(ct:ComplexType) return ct.toType().sure();
|
||||||
|
assertEquals('StdTypes.Float', tink.macro.Types.deduceCommonType([(macro:Float), (macro:Int)].map(ct2t)).sure().toComplex().toString());
|
||||||
|
assertEquals('Types.CommonI1', tink.macro.Types.deduceCommonType([(macro:Types.CommonA), (macro:Types.CommonB), (macro:Types.CommonC)].map(ct2t)).sure().toComplex().toString());
|
||||||
|
assertEquals('Types.CommonI2', tink.macro.Types.deduceCommonType([(macro:Types.CommonB), (macro:Types.CommonC)].map(ct2t)).sure().toComplex().toString());
|
||||||
|
// assertEquals('Types.CommonI3', tink.macro.Types.deduceCommonType([(macro:Types.CommonC)].map(ct2t)).sure().toComplex().toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
interface CommonI1 {}
|
||||||
|
interface CommonI2 {}
|
||||||
|
interface CommonI3 {}
|
||||||
|
class CommonA implements CommonI1 {}
|
||||||
|
class CommonB implements CommonI2 implements CommonI1 {}
|
||||||
|
class CommonC implements CommonI3 implements CommonI2 implements CommonI1 {}
|
||||||
10
tests/nested/Dummy.hx
Normal file
10
tests/nested/Dummy.hx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package nested;
|
||||||
|
|
||||||
|
class Dummy {
|
||||||
|
public function new() {}
|
||||||
|
static public var p(default, never) = new Private();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Private {
|
||||||
|
public function new() {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user