GenericError type (Type conflict with haxe.macro.Type)

This commit is contained in:
Dima Granetchi
2014-12-08 21:20:57 +02:00
parent 85acc088fd
commit a7968c65af
4 changed files with 16 additions and 16 deletions
+8 -8
View File
@@ -1,7 +1,7 @@
package bindx; package bindx;
#if macro #if macro
import bindx.Error; import bindx.GenericError;
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.macro.Type; import haxe.macro.Type;
import haxe.macro.Context; import haxe.macro.Context;
@@ -68,14 +68,14 @@ class Bind {
if (res.error != null) res.error.contextError(); if (res.error != null) res.error.contextError();
} catch (e:FatalError) { } catch (e:FatalError) {
e.contextFatal(); e.contextFatal();
} catch (e:bindx.Error) { } catch (e:GenericError) {
e.contextError(); e.contextError();
}; };
return res; return res;
} }
static function checkField(f:Expr):{e:Expr, field:ClassField, error:bindx.Error} { static function checkField(f:Expr):{e:Expr, field:ClassField, error:GenericError} {
var error:bindx.Error; var error:GenericError;
switch (f.expr) { switch (f.expr) {
case EField(e, field): case EField(e, field):
var type = Context.typeof(e); var type = Context.typeof(e);
@@ -85,7 +85,7 @@ class Bind {
return {e:f, field:null, error:error}; return {e:f, field:null, error:error};
} }
if (!isBindable(classType)) { if (!isBindable(classType)) {
error = new bindx.Error('\'${e.toString()}\' must be bindx.IBindable', e.pos); error = new GenericError('\'${e.toString()}\' must be bindx.IBindable', e.pos);
} }
var field:ClassField = classType.findField(field, null); var field:ClassField = classType.findField(field, null);
@@ -95,17 +95,17 @@ class Bind {
} }
if (!field.hasBindableMeta()) { if (!field.hasBindableMeta()) {
error = new bindx.Error('\'${e.toString()}.${field.name}\' is not bindable', field.pos); error = new GenericError('\'${e.toString()}.${field.name}\' is not bindable', field.pos);
} }
return {e:e, field:field, error:error}; return {e:e, field:field, error:error};
case EConst(CIdent(_)): case EConst(CIdent(_)):
return {e:f, field:null, error:new bindx.Error('Can\'t bind \'${f.toString()}\'. Please use \'this.${f.toString()}\'', f.pos)}; return {e:f, field:null, error:new GenericError('Can\'t bind \'${f.toString()}\'. Please use \'this.${f.toString()}\'', f.pos)};
case _: case _:
} }
return {e:f, field:null, error:new bindx.Error('\'${f.toString()}\' is not bindable', f.pos)}; return {e:f, field:null, error:new GenericError('\'${f.toString()}\' is not bindable', f.pos)};
} }
static function isBindable(classType:ClassType):Bool { static function isBindable(classType:ClassType):Bool {
+5 -5
View File
@@ -2,7 +2,7 @@ package bindx;
#if macro #if macro
import bindx.Error; import bindx.GenericError;
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.macro.MacroStringTools; import haxe.macro.MacroStringTools;
import haxe.macro.Type; import haxe.macro.Type;
@@ -55,7 +55,7 @@ class BindExt {
static function internalBindChain(expr:Expr, listener:Expr):Expr { static function internalBindChain(expr:Expr, listener:Expr):Expr {
var zeroListener = listenerName(0, ""); var zeroListener = listenerName(0, "");
var chain = null; var chain = null;
try { chain = warnPrepareChain(expr, macro $i{ zeroListener }); } catch (e:bindx.Error) e.contextError(); try { chain = warnPrepareChain(expr, macro $i{ zeroListener }); } catch (e:GenericError) e.contextError();
return macro (function ($zeroListener):Void->Void return macro (function ($zeroListener):Void->Void
$b { chain.init.concat(chain.bind).concat([macro return function ():Void $b { chain.unbind }]) } $b { chain.init.concat(chain.bind).concat([macro return function ():Void $b { chain.unbind }]) }
@@ -108,7 +108,7 @@ class BindExt {
var c = null; var c = null;
try { try {
c = warnPrepareChain(expr, macro $i { zeroListener }, pre, true); c = warnPrepareChain(expr, macro $i { zeroListener }, pre, true);
} catch (e:bindx.Error) { } catch (e:GenericError) {
Warn.w('${expr.toString()} is not bindable.', e.pos, WarnPriority.ALL); Warn.w('${expr.toString()} is not bindable.', e.pos, WarnPriority.ALL);
} }
if (c != null) { if (c != null) {
@@ -227,7 +227,7 @@ class BindExt {
} }
var bindableNum = fields.fold(function (it, n) return n += it.bindable ? 1 : 0, 0); var bindableNum = fields.fold(function (it, n) return n += it.bindable ? 1 : 0, 0);
if (bindableNum == 0) { if (bindableNum == 0) {
throw new bindx.Error('${expr.toString()} is not bindable.', expr.pos); throw new GenericError('${expr.toString()} is not bindable.', expr.pos);
return null; return null;
} }
if (first != null) if (first != null)
@@ -315,7 +315,7 @@ class BindExt {
} }
if (zeroListener == null || zeroListener.f.bindable == false) if (zeroListener == null || zeroListener.f.bindable == false)
throw new bindx.Error('${expr.toString()} is not bindable.', expr.pos); throw new GenericError('${expr.toString()} is not bindable.', expr.pos);
var zeroName = zeroListener.f.e.toString(); var zeroName = zeroListener.f.e.toString();
if (zeroName != "this") if (zeroName != "this")
+1 -1
View File
@@ -1,6 +1,6 @@
package bindx; package bindx;
import bindx.Error; import bindx.GenericError;
import haxe.macro.Type; import haxe.macro.Type;
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.macro.Context; import haxe.macro.Context;
@@ -23,9 +23,9 @@ class Warn {
} }
} }
class FatalError extends Error {} class FatalError extends GenericError {}
class Error { class GenericError {
public var pos(default, null):Position; public var pos(default, null):Position;
public var message(default, null):String; public var message(default, null):String;