Skip to content

Commit 1aef7d5

Browse files
authored
Merge pull request #11 from simonbyrne/sb/nested-where
Allow multiple where statements
2 parents 704a91e + a3449e1 commit 1aef7d5

File tree

6 files changed

+61
-13
lines changed

6 files changed

+61
-13
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
on:
3+
- pull_request
4+
jobs:
5+
test:
6+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
version:
12+
- '1.0'
13+
- '1.4'
14+
- '1.5'
15+
- 'nightly'
16+
os:
17+
- ubuntu-latest
18+
- macOS-latest
19+
- windows-latest
20+
arch:
21+
- x64
22+
steps:
23+
- uses: actions/checkout@v2
24+
- uses: julia-actions/setup-julia@v1
25+
with:
26+
version: ${{ matrix.version }}
27+
arch: ${{ matrix.arch }}
28+
- uses: actions/cache@v1
29+
env:
30+
cache-name: cache-artifacts
31+
with:
32+
path: ~/.julia/artifacts
33+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
34+
restore-keys: |
35+
${{ runner.os }}-test-${{ env.cache-name }}-
36+
${{ runner.os }}-test-
37+
${{ runner.os }}-
38+
- uses: julia-actions/julia-buildpkg@latest
39+
- uses: julia-actions/julia-runtest@latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Manifest.toml

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

Project.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
name = "KeywordDispatch"
22
uuid = "5888135b-5456-5c80-a1b6-c91ef8180460"
33
authors = ["Simon Byrne <[email protected]>"]
4-
version = "0.3.0"
4+
version = "0.3.1"
55

6-
[deps]
6+
[compat]
7+
julia = "1.0"
8+
9+
[extras]
710
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
11+
12+
[targets]
13+
test = ["Test"]

src/KeywordDispatch.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ argtype(x::Expr) = x.head == :(::) ? x.args[end] : error("unexpected expression
5454
function unwrap_where(expr)
5555
stack = Any[]
5656
while expr isa Expr && expr.head == :where
57-
push!(stack, expr.args[2])
57+
append!(stack, expr.args[2:end])
5858
expr = expr.args[1]
5959
end
6060
expr, stack

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,15 @@ end
251251

252252
@test f(alpha=0,beta=0) == 3
253253
end
254+
255+
@testset "multiple where clauses" begin
256+
# based on https://github.com/simonbyrne/KeywordDispatch.jl/issues/9
257+
@kwdispatch f(x::T) where {T}
258+
259+
@kwmethod f(x::T; y::TI) where {T, TI <: Vector{T}} = y
260+
261+
@test f(1.0,y=[1.0,2.0]) == [1.0,2.0]
262+
@test f(1,y=[1,2]) == [1,2]
263+
264+
@test_throws KeywordMethodError f(1,y=[1.0,2.0])
265+
end

0 commit comments

Comments
 (0)