Skip to content

Commit 54bfc9d

Browse files
authored
Make @interface overloads take types, not instances (#5)
1 parent 3455bb2 commit 54bfc9d

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ struct SparseArrayInterface end
6060
Define interface functions.
6161

6262
````julia
63-
@interface SparseArrayInterface() function Base.getindex(a, I::Int...)
63+
@interface SparseArrayInterface function Base.getindex(a, I::Int...)
6464
checkbounds(a, I...)
6565
!isstored(a, I...) && return getunstoredindex(a, I...)
6666
return getstoredindex(a, I...)
6767
end
68-
@interface SparseArrayInterface() function Base.setindex!(a, value, I::Int...)
68+
@interface SparseArrayInterface function Base.setindex!(a, value, I::Int...)
6969
checkbounds(a, I...)
7070
iszero(value) && return a
7171
if !isstored(a, I...)

examples/README.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ using Test: @test
5959
struct SparseArrayInterface end
6060

6161
# Define interface functions.
62-
@interface SparseArrayInterface() function Base.getindex(a, I::Int...)
62+
@interface SparseArrayInterface function Base.getindex(a, I::Int...)
6363
checkbounds(a, I...)
6464
!isstored(a, I...) && return getunstoredindex(a, I...)
6565
return getstoredindex(a, I...)
6666
end
67-
@interface SparseArrayInterface() function Base.setindex!(a, value, I::Int...)
67+
@interface SparseArrayInterface function Base.setindex!(a, value, I::Int...)
6868
checkbounds(a, I...)
6969
iszero(value) && return a
7070
if !isstored(a, I...)

src/interface_macro.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ or:
2727
```
2828
to:
2929
```julia
30-
Derive.call(::typeof(SparseArrayInterface()), Base.getindex, a, I...)
30+
Derive.call(SparseArrayInterface(), Base.getindex, a, I...)
3131
```
3232
=#
3333
function interface_call(interface::Union{Symbol,Expr}, func::Expr)
@@ -48,7 +48,7 @@ Rewrite:
4848
```
4949
to:
5050
```julia
51-
Derive.call(::typeof(SparseArrayInterface()), Base.getindex, a, I...)
51+
Derive.call(SparseArrayInterface(), Base.getindex, a, I...)
5252
```
5353
=#
5454
function interface_ref(interface::Union{Symbol,Expr}, func::Expr)
@@ -65,7 +65,7 @@ Rewrite:
6565
```
6666
to:
6767
```julia
68-
Derive.call(::typeof(SparseArrayInterface()), Base.setindex!, a, value, I...)
68+
Derive.call(SparseArrayInterface(), Base.setindex!, a, value, I...)
6969
```
7070
=#
7171
function interface_setref(interface::Union{Symbol,Expr}, func::Expr)
@@ -78,14 +78,14 @@ end
7878
#=
7979
Rewrite:
8080
```julia
81-
@interface SparseArrayInterface() function Base.getindex(a, I::Int...)
81+
@interface SparseArrayInterface function Base.getindex(a, I::Int...)
8282
!isstored(a, I...) && return getunstoredindex(a, I...)
8383
return getstoredindex(a, I...)
8484
end
8585
```
8686
to:
8787
```julia
88-
function Derive.call(::typeof(SparseArrayInterface()), Base.getindex, a, I::Int...)
88+
function Derive.call(::SparseArrayInterface, Base.getindex, a, I::Int...)
8989
!isstored(a, I...) && return getunstoredindex(a, I...)
9090
return getstoredindex(a, I...)
9191
end
@@ -98,7 +98,7 @@ function interface_definition(interface::Union{Symbol,Expr}, func::Expr)
9898
# We use `Core.Typeof` here because `name` can either be a function or type,
9999
# and `typeof(T::Type)` outputs things like `DataType`, `UnionAll`, etc.
100100
# while `Core.Typeof(T::Type)` returns `Type{T}`.
101-
new_args = [:(::typeof($interface)); :(::Core.Typeof($name)); args]
101+
new_args = [:(::$interface); :(::Core.Typeof($name)); args]
102102
return globalref_derive(
103103
codegen_ast(
104104
JLFunction(; name=new_name, args=new_args, kwargs, rettype, whereparams, body)

0 commit comments

Comments
 (0)