Skip to content

Commit

Permalink
Merge pull request #24 from kevinresol/type_get_pos
Browse files Browse the repository at this point in the history
Get Position from a Type
  • Loading branch information
kevinresol committed Feb 23, 2019
2 parents b5605e4 + 86fa47e commit 3d9aec8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/tink/macro/Types.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3d9aec8

Please sign in to comment.