@@ -3618,82 +3618,48 @@ def test_multi_arity_recur(self, lcompile: CompileFn):
3618
3618
assert 10 == lcompile ("(+++ 1 2 3 4)" )
3619
3619
assert 15 == lcompile ("(+++ 1 2 3 4 5)" )
3620
3620
3621
- def test_disallow_recur_in_special_forms (self , lcompile : CompileFn ):
3622
- with pytest .raises (compiler .CompilerException ):
3623
- lcompile ('(fn [a] (def b (recur "a")))' )
3624
-
3625
- with pytest .raises (compiler .CompilerException ):
3626
- lcompile ('(fn [a] (import* (recur "a")))' )
3627
-
3628
- with pytest .raises (compiler .CompilerException ):
3629
- lcompile ('(fn [a] (.join "" (recur "a")))' )
3630
-
3631
- with pytest .raises (compiler .CompilerException ):
3632
- lcompile ('(fn [a] (.-p (recur "a")))' )
3633
-
3634
- with pytest .raises (compiler .CompilerException ):
3635
- lcompile ('(fn [a] (throw (recur "a"))))' )
3636
-
3637
- with pytest .raises (compiler .CompilerException ):
3638
- lcompile ('(fn [a] (var (recur "a"))))' )
3639
-
3640
- def test_disallow_recur_outside_tail (self , lcompile : CompileFn ):
3641
- with pytest .raises (compiler .CompilerException ):
3642
- lcompile ("(recur)" )
3643
-
3644
- with pytest .raises (compiler .CompilerException ):
3645
- lcompile ("(do (recur))" )
3646
-
3647
- with pytest .raises (compiler .CompilerException ):
3648
- lcompile ("(if true (recur) :b)" )
3649
-
3650
- with pytest .raises (compiler .CompilerException ):
3651
- lcompile ('(fn [a] (do (recur "a") :b))' )
3652
-
3653
- with pytest .raises (compiler .CompilerException ):
3654
- lcompile ('(fn [a] (if (recur "a") :a :b))' )
3655
-
3656
- with pytest .raises (compiler .CompilerException ):
3657
- lcompile ('(fn [a] (if (recur "a") :a))' )
3658
-
3659
- with pytest .raises (compiler .CompilerException ):
3660
- lcompile ('(fn [a] (let [a (recur "a")] a))' )
3661
-
3662
- with pytest .raises (compiler .CompilerException ):
3663
- lcompile ('(fn [a] (let [a (do (recur "a"))] a))' )
3664
-
3665
- with pytest .raises (compiler .CompilerException ):
3666
- lcompile ('(fn [a] (let [a (do :b (recur "a"))] a))' )
3667
-
3668
- with pytest .raises (compiler .CompilerException ):
3669
- lcompile ('(fn [a] (let [a (do (recur "a") :c)] a))' )
3670
-
3671
- with pytest .raises (compiler .CompilerException ):
3672
- lcompile ('(fn [a] (let [a "a"] (recur a) a))' )
3673
-
3674
- with pytest .raises (compiler .CompilerException ):
3675
- lcompile ('(fn [a] (loop* [a (recur "a")] a))' )
3676
-
3677
- with pytest .raises (compiler .CompilerException ):
3678
- lcompile ('(fn [a] (loop* [a (do (recur "a"))] a))' )
3679
-
3680
- with pytest .raises (compiler .CompilerException ):
3681
- lcompile ('(fn [a] (loop* [a (do :b (recur "a"))] a))' )
3682
-
3683
- with pytest .raises (compiler .CompilerException ):
3684
- lcompile ('(fn [a] (loop* [a (do (recur "a") :c)] a))' )
3685
-
3686
- with pytest .raises (compiler .CompilerException ):
3687
- lcompile ('(fn [a] (loop* [a "a"] (recur a) a))' )
3688
-
3689
- with pytest .raises (compiler .CompilerException ):
3690
- lcompile ("(fn [a] (try (do (recur a) :b) (catch AttributeError _ nil)))" )
3691
-
3621
+ @pytest .mark .parametrize (
3622
+ "code" ,
3623
+ [
3624
+ '(fn [a] (def b (recur "a")))' ,
3625
+ '(fn [a] (import* (recur "a")))' ,
3626
+ '(fn [a] (.join "" (recur "a")))' ,
3627
+ '(fn [a] (.-p (recur "a")))' ,
3628
+ '(fn [a] (throw (recur "a"))))' ,
3629
+ '(fn [a] (var (recur "a"))))' ,
3630
+ ],
3631
+ )
3632
+ def test_disallow_recur_in_special_forms (self , lcompile : CompileFn , code : str ):
3692
3633
with pytest .raises (compiler .CompilerException ):
3693
- lcompile ("(fn [a] (try :b (catch AttributeError _ (do (recur :a) :c))))" )
3634
+ lcompile (code )
3694
3635
3636
+ @pytest .mark .parametrize (
3637
+ "code" ,
3638
+ [
3639
+ "(recur)" ,
3640
+ "(do (recur))" ,
3641
+ "(if true (recur) :b)" ,
3642
+ '(fn [a] (do (recur "a") :b))' ,
3643
+ '(fn [a] (if (recur "a") :a :b))' ,
3644
+ '(fn [a] (if (recur "a") :a))' ,
3645
+ '(fn [a] (let [a (recur "a")] a))' ,
3646
+ '(fn [a] (let [a (do (recur "a"))] a))' ,
3647
+ '(fn [a] (let [a (do :b (recur "a"))] a))' ,
3648
+ '(fn [a] (let [a (do (recur "a") :c)] a))' ,
3649
+ '(fn [a] (let [a "a"] (recur a) a))' ,
3650
+ '(fn [a] (loop* [a (recur "a")] a))' ,
3651
+ '(fn [a] (loop* [a (do (recur "a"))] a))' ,
3652
+ '(fn [a] (loop* [a (do :b (recur "a"))] a))' ,
3653
+ '(fn [a] (loop* [a (do (recur "a") :c)] a))' ,
3654
+ '(fn [a] (loop* [a "a"] (recur a) a))' ,
3655
+ "(fn [a] (try (do (recur a) :b) (catch AttributeError _ nil)))" ,
3656
+ "(fn [a] (try :b (catch AttributeError _ (do (recur :a) :c))))" ,
3657
+ "(fn [a] (try :b (finally (do (recur :a) :c))))" ,
3658
+ ],
3659
+ )
3660
+ def test_disallow_recur_outside_tail (self , lcompile : CompileFn , code : str ):
3695
3661
with pytest .raises (compiler .CompilerException ):
3696
- lcompile ("(fn [a] (try :b (finally (do (recur :a) :c))))" )
3662
+ lcompile (code )
3697
3663
3698
3664
def test_single_arity_named_anonymous_fn_recursion (self , lcompile : CompileFn ):
3699
3665
code = """
@@ -4106,6 +4072,53 @@ def test_nested_bare_sym_will_not_resolve(self, lcompile: CompileFn):
4106
4072
with pytest .raises (compiler .CompilerException ):
4107
4073
lcompile ("basilisp.lang.map.MapEntry.of" )
4108
4074
4075
+ def test_local_deftype_classmethod_resolves (self , lcompile : CompileFn ):
4076
+ Point = lcompile (
4077
+ """
4078
+ (import* abc)
4079
+ (def WithCls
4080
+ (python/type "WithCls"
4081
+ #py (abc/ABC)
4082
+ #py {"create"
4083
+ (python/classmethod
4084
+ (abc/abstractmethod
4085
+ (fn [cls])))}))
4086
+ (deftype* Point [x y z]
4087
+ :implements [WithCls]
4088
+ (^:classmethod create [cls x y z]
4089
+ [cls x y z]))
4090
+ """
4091
+ )
4092
+
4093
+ assert vec .v (Point , 1 , 2 , 3 ) == lcompile ("(Point/create 1 2 3)" )
4094
+
4095
+ with pytest .raises (compiler .CompilerException ):
4096
+ lcompile ("(Point/make 1 2 3)" )
4097
+
4098
+ def test_local_deftype_staticmethod_resolves (self , lcompile : CompileFn ):
4099
+ Point = lcompile (
4100
+ """
4101
+ (import* abc)
4102
+ (def WithStatic
4103
+ (python/type "WithStatic"
4104
+ #py (abc/ABC)
4105
+ #py {"dostatic"
4106
+ (python/staticmethod
4107
+ (abc/abstractmethod
4108
+ (fn [])))}))
4109
+ (deftype* Point [x y z]
4110
+ :implements [WithStatic]
4111
+ (^:staticmethod dostatic [arg1 arg2]
4112
+ [arg1 arg2]))
4113
+ """
4114
+ )
4115
+
4116
+ assert Point .dostatic is lcompile ("Point/dostatic" )
4117
+ assert vec .v (kw .keyword ("a" ), 2 ) == lcompile ("(Point/dostatic :a 2)" )
4118
+
4119
+ with pytest .raises (compiler .CompilerException ):
4120
+ lcompile ("(Point/do-non-static 1 2)" )
4121
+
4109
4122
def test_aliased_namespace_not_hidden_by_python_module (
4110
4123
self , lcompile : CompileFn , monkeypatch : MonkeyPatch
4111
4124
):
0 commit comments