Skip to content

Commit db90631

Browse files
authored
allow where syntax in constructor definitions (#35861)
1 parent f12cde0 commit db90631

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Julia v1.6 Release Notes
44
New language features
55
---------------------
66

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

810
Language changes
911
----------------

src/julia-syntax.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@
11111111
(and (not (any kwarg? argl)) (not (and (pair? argl)
11121112
(pair? (car argl))
11131113
(eq? (caar argl) 'parameters))))))
1114-
(name (if (or (decl? name) (and (pair? name) (eq? (car name) 'curly)))
1114+
(name (if (or (decl? name) (and (pair? name) (memq (car name) '(curly where))))
11151115
#f name)))
11161116
(expand-forms
11171117
(method-def-expr name sparams argl body rett))))

test/core.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4708,6 +4708,11 @@ let ft = Base.datatype_fieldtypes
47084708
@test !isdefined(ft(B12238.body.body)[1], :instance) # has free type vars
47094709
end
47104710

4711+
# `where` syntax in constructor definitions
4712+
(A12238{T} where T<:Real)(x) = 0
4713+
@test A12238{<:Real}(0) == 0
4714+
@test_throws MethodError A12238{<:Integer}(0)
4715+
47114716
# issue #16315
47124717
let a = Any[]
47134718
@noinline f() = a[end]

0 commit comments

Comments
 (0)