Skip to content

Commit

Permalink
fix error messages position
Browse files Browse the repository at this point in the history
  • Loading branch information
botsman committed Feb 7, 2021
1 parent 74ee1af commit 73ba013
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"javascript"
],
"description": "This library provides a macros to add 'async' and 'await' keywords for Python and JavaScript and does nothing for other platoforms.",
"version": "0.3.5",
"version": "0.3.6",
"classPath": "src",
"releasenote": "Mare cases handled. Improve throwed errors",
"contributors": [
Expand Down
26 changes: 15 additions & 11 deletions src/hxasync/AsyncMacro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AsyncMacro {
handleAny(f.expr, asyncContext);
default:
if (asyncContext) {
throw new Error("async can be applied only to a function field type", Context.currentPos());
Context.error("async can be applied only to a function field type", field.pos);
}
}
}
Expand All @@ -66,27 +66,27 @@ class AsyncMacro {
return false;
}

public static function handleEMeta(expr: Expr, isAsyncContext: Bool) {
public static inline function handleEMeta(expr: Expr, isAsyncContext: Bool) {
switch expr.expr {
case EMeta(s, e):
if (s.name == "await") {
if (!isAsyncContext) {
throw new Error("await allowed only inside async function", Context.currentPos());
Context.error("await allowed only inside async function", e.pos);
}
transformToAwait(expr);
} else if (s.name == "async") {
switch e.expr {
case EFunction(kind, f):
transformToAsync(f);
handleEFunction(f, kind, true);
handleEFunction(f, kind, true, e.pos);
default:
throw new Error("async only allowed to be used with functions", Context.currentPos());
Context.error("async only allowed to be used with functions", e.pos);
}
} else {
handleAny(e, isAsyncContext);
}
default:
throw new Error("Expr is not EMeta", Context.currentPos());
Context.error("Expr is not EMeta", expr.pos);
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ class AsyncMacro {
handleAny(variable.expr, isAsyncContext);
}
case EFunction(kind, f):
handleEFunction(f, kind, false);
handleEFunction(f, kind, false, expr.pos);
case EObjectDecl(fields):
for (field in fields) {
handleAny(field.expr, isAsyncContext);
Expand Down Expand Up @@ -178,16 +178,20 @@ class AsyncMacro {
case null:
null;
case other:
throw new Error('Unexpected expression ${other}', Context.currentPos());
Context.error('Unexpected expression ${other}', expr.pos);
null;
}
}

public static function handleEFunction(fun: Function, kind: FunctionKind, isAsyncContext: Bool) {
public static function handleEFunction(fun: Function, kind: FunctionKind, isAsyncContext: Bool, pos: Position) {
if (isAsyncContext) {
switch kind {
case FNamed(name, inlined):
if (inlined) {
throw new Error("Inline function can not be async", Context.currentPos());
if (fun.expr != null) {
Context.error("Inline function can not be async", fun.expr.pos);
}
Context.error("Inline function can not be async", pos);
}
default:
null;
Expand Down Expand Up @@ -429,7 +433,7 @@ class AsyncMacro {
processAwaitedFuncArgs(metaE);
e.expr = (macro hxasync.AsyncMacroUtils.await(${metaE})).expr;
default:
throw new Error("Invalid expression", Context.currentPos());
Context.error("Invalid expression", e.pos);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/hxasync/Awaitable.hx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package hxasync;

abstract Awaitable<T>(T) from T to T {}
abstract Awaitable<T>(T) from T {}

0 comments on commit 73ba013

Please sign in to comment.