Skip to content

Commit

Permalink
allow where syntax in constructor definitions (JuliaLang#35861)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 13, 2020
1 parent f12cde0 commit db90631
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Julia v1.6 Release Notes
New language features
---------------------

* Types written with `where` syntax can now be used to define constructors, e.g.
`(Foo{T} where T)(x) = ...`.

Language changes
----------------
Expand Down
2 changes: 1 addition & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@
(and (not (any kwarg? argl)) (not (and (pair? argl)
(pair? (car argl))
(eq? (caar argl) 'parameters))))))
(name (if (or (decl? name) (and (pair? name) (eq? (car name) 'curly)))
(name (if (or (decl? name) (and (pair? name) (memq (car name) '(curly where))))
#f name)))
(expand-forms
(method-def-expr name sparams argl body rett))))
Expand Down
5 changes: 5 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4708,6 +4708,11 @@ let ft = Base.datatype_fieldtypes
@test !isdefined(ft(B12238.body.body)[1], :instance) # has free type vars
end

# `where` syntax in constructor definitions
(A12238{T} where T<:Real)(x) = 0
@test A12238{<:Real}(0) == 0
@test_throws MethodError A12238{<:Integer}(0)

# issue #16315
let a = Any[]
@noinline f() = a[end]
Expand Down

0 comments on commit db90631

Please sign in to comment.