Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow where syntax in constructor definitions #35861

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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