(extends) and (implements) for pure-kiss classes
This commit is contained in:
@@ -580,6 +580,33 @@ class SpecialForms {
|
||||
return none(wholeExp);
|
||||
};
|
||||
|
||||
k.doc("extends", 1, 1, "(extends <Class>)");
|
||||
map["extends"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
requireContext(wholeExp, "extends");
|
||||
var type = context.getType();
|
||||
type.kind = switch (type.kind) {
|
||||
case TDClass(null, interfaces, false, false, false):
|
||||
TDClass(Reader.toString(exps[0].def).asTypePath(), interfaces, false, false, false);
|
||||
default:
|
||||
throw KissError.fromExp(wholeExp, '${type.name} must be a class without a superclass');
|
||||
}
|
||||
return none(wholeExp);
|
||||
};
|
||||
|
||||
k.doc("implements", 1, null, "(implements <Interfaces...>)");
|
||||
map["implements"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
requireContext(wholeExp, "implements");
|
||||
var type = context.getType();
|
||||
var interfaces = [for (exp in exps) Reader.toString(exp.def).asTypePath()];
|
||||
type.kind = switch (type.kind) {
|
||||
case TDClass(superClass, [], false, false, false):
|
||||
TDClass(superClass, interfaces, false, false, false);
|
||||
default:
|
||||
throw KissError.fromExp(wholeExp, '${type.name} must be a class without any interfaces');
|
||||
}
|
||||
return none(wholeExp);
|
||||
};
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
5
kiss/src/test/BasicInterface.hx
Normal file
5
kiss/src/test/BasicInterface.hx
Normal file
@@ -0,0 +1,5 @@
|
||||
package test;
|
||||
|
||||
interface BasicInterface {
|
||||
public var otherNum(default,null):Int;
|
||||
}
|
@@ -2,8 +2,16 @@
|
||||
(importAs test.OtherPureKissClass Alias)
|
||||
(using test.OtherPureKissClass)
|
||||
|
||||
(extends OtherPureKissClass)
|
||||
(implements test.BasicInterface)
|
||||
|
||||
(defNew [num &prop :Int otherNum]
|
||||
(super num))
|
||||
|
||||
(function test []
|
||||
(assert (= (.extensionMethod "string") "EXTENDED"))
|
||||
(let [instance (new OtherPureKissClass 5)
|
||||
other (new Alias 5)]
|
||||
(assert (= instance.num other.num 5))))
|
||||
other (new Alias 5)
|
||||
third (new PureKissClass 5 6)]
|
||||
(assert (= instance.num other.num third.num 5))
|
||||
(assert (= third.otherNum 6))))
|
Reference in New Issue
Block a user