From 86fa47eb0df91b2f0b790b749cf650dc9c4be1b3 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Sat, 23 Feb 2019 22:37:17 +0800 Subject: [PATCH] Get Position from a Type --- src/tink/macro/Types.hx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/tink/macro/Types.hx b/src/tink/macro/Types.hx index c88ca48..d7d61fb 100644 --- a/src/tink/macro/Types.hx +++ b/src/tink/macro/Types.hx @@ -101,6 +101,22 @@ class Types { case TInst(t, _): Success(t.get().statics.get()); default: Failure('type has no statics'); } + + + static public function getPosition(t:Type) + return + switch t { + case TInst(_.get() => {pos: pos}, _) + | TAbstract(_.get() => {pos: pos}, _) + | TType(_.get() => {pos: pos}, _) + | TEnum(_.get() => {pos: pos}, _) : Success(pos); + case TMono(ref): getPosition(ref.get()); + case TLazy(f): getPosition(f()); + case TDynamic(v) if(v != null): getPosition(v); + default: Failure('type "$t" has no position'); + } + + static public function toString(t:ComplexType) return new Printer().printComplexType(t);