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

deprecate special "inner constructor" syntax #20308

Merged
merged 1 commit into from
Feb 7, 2017
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
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ New language features
Language changes
----------------

* "Inner constructor" syntax for parametric types is deprecated. For example,
in this definition:
```
type Foo{T,S<:Real}
x
Foo(x) = new(x)
end
```
the syntax `Foo(x) = new(x)` actually defined a constructor for `Foo{T,S}`,
i.e. the case where the type parameters are specified. For clarity, this
definition now must be written as `Foo{T,S}(x) where {T,S<:Real} = new(x)`. ([#11310])

* Multi-line and single-line nonstandard command literals have been added. A
nonstandard command literal is like a nonstandard string literal, but the
syntax uses backquotes (``` ` ```) instead of double quotes, and the
Expand Down
9 changes: 5 additions & 4 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1014,10 +1014,10 @@ type HistoryPrompt{T<:HistoryProvider} <: TextInterface
hp::T
complete
keymap_dict::Dict{Char,Any}
HistoryPrompt(hp) = new(hp, EmptyCompletionProvider())
HistoryPrompt{T}(hp) where T<:HistoryProvider = new(hp, EmptyCompletionProvider())
end

HistoryPrompt{T<:HistoryProvider}(hp::T) = HistoryPrompt{T}(hp)
HistoryPrompt(hp::T) where T<:HistoryProvider = HistoryPrompt{T}(hp)
init_state(terminal, p::HistoryPrompt) = SearchState(terminal, p, true, IOBuffer(), IOBuffer())

type PrefixSearchState <: ModeState
Expand Down Expand Up @@ -1054,10 +1054,11 @@ type PrefixHistoryPrompt{T<:HistoryProvider} <: TextInterface
parent_prompt::Prompt
complete
keymap_dict::Dict{Char,Any}
PrefixHistoryPrompt(hp, parent_prompt) = new(hp, parent_prompt, EmptyCompletionProvider())
PrefixHistoryPrompt{T}(hp, parent_prompt) where T<:HistoryProvider =
new(hp, parent_prompt, EmptyCompletionProvider())
end

PrefixHistoryPrompt{T<:HistoryProvider}(hp::T, parent_prompt) = PrefixHistoryPrompt{T}(hp, parent_prompt)
PrefixHistoryPrompt(hp::T, parent_prompt) where T<:HistoryProvider = PrefixHistoryPrompt{T}(hp, parent_prompt)
init_state(terminal, p::PrefixHistoryPrompt) = PrefixSearchState(terminal, p, "", IOBuffer())

write_prompt(terminal, s::PrefixSearchState) = write_prompt(terminal, s.histprompt.parent_prompt)
Expand Down
4 changes: 2 additions & 2 deletions base/atomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Atomic operations use an `atomic_` prefix, such as `atomic_add!`,
"""
type Atomic{T<:AtomicTypes}
value::T
Atomic() = new(zero(T))
Atomic(value) = new(value)
Atomic{T}() where T<:AtomicTypes = new(zero(T))
Atomic{T}(value) where T<:AtomicTypes = new(value)
end

Atomic() = Atomic{Int}()
Expand Down
4 changes: 2 additions & 2 deletions base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ immutable Nullable{T}
hasvalue::Bool
value::T

Nullable() = new(false)
Nullable(value::T, hasvalue::Bool=true) = new(hasvalue, value)
Nullable{T}() where T = new(false)
Nullable{T}(value::T, hasvalue::Bool=true) where T = new(hasvalue, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some form of brackets here, please

end
4 changes: 2 additions & 2 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type BitArray{N} <: DenseArray{Bool, N}
chunks::Vector{UInt64}
len::Int
dims::NTuple{N,Int}
function BitArray(dims::Vararg{Int,N})
function BitArray{N}(dims::Vararg{Int,N}) where N
n = 1
i = 1
for d in dims
Expand Down Expand Up @@ -36,7 +36,7 @@ Construct an uninitialized `BitArray` with the given dimensions.
Behaves identically to the [`Array`](@ref) constructor.
"""
BitArray(dims::Integer...) = BitArray(map(Int,dims))
BitArray{N}(dims::NTuple{N,Int}) = BitArray{N}(dims...)
BitArray(dims::NTuple{N,Int}) where N = BitArray{N}(dims...)

typealias BitVector BitArray{1}
typealias BitMatrix BitArray{2}
Expand Down
4 changes: 2 additions & 2 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ Void() = nothing

immutable VecElement{T}
value::T
VecElement(value::T) = new(value) # disable converting constructor in Core
VecElement{T}(value::T) where T = new(value) # disable converting constructor in Core
end
VecElement{T}(arg::T) = VecElement{T}(arg)
VecElement(arg::T) where T = VecElement{T}(arg)

# used by lowering of splicing unquote
splicedexpr(hd::Symbol, args::Array{Any,1}) = (e=Expr(hd); e.args=args; e)
Expand Down
8 changes: 4 additions & 4 deletions base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ type Channel{T} <: AbstractChannel
# Used when sz_max == 0, i.e., an unbuffered channel.
takers::Array{Condition}

function Channel(sz::Float64)
function Channel{T}(sz::Float64) where T
if sz == Inf
Channel{T}(typemax(Int))
else
Channel{T}(convert(Int, sz))
end
end
function Channel(sz::Integer)
function Channel{T}(sz::Integer) where T
if sz < 0
throw(ArgumentError("Channel size must be either 0, a positive integer or Inf"))
end
new(Condition(), Condition(), :open, Nullable{Exception}(), Array{T}(0), sz, Array{Condition}(0))
end

# deprecated empty constructor
function Channel()
function Channel{T}() where T
depwarn(string("The empty constructor Channel() is deprecated. ",
"The channel size needs to be specified explictly. ",
"Defaulting to Channel{$T}(32)."), :Channel)
Expand Down Expand Up @@ -364,7 +364,7 @@ show(io::IO, c::Channel) = print(io, "$(typeof(c))(sz_max:$(c.sz_max),sz_curr:$(
type ChannelIterState{T}
hasval::Bool
val::T
ChannelIterState(x) = new(x)
ChannelIterState{T}(has::Bool) where T = new(has)
end

start{T}(c::Channel{T}) = ChannelIterState{T}(false)
Expand Down
6 changes: 3 additions & 3 deletions base/dft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ type ScaledPlan{T,P,N} <: Plan{T}
p::P
scale::N # not T, to avoid unnecessary promotion to Complex
pinv::Plan
ScaledPlan(p, scale) = new(p, scale)
ScaledPlan{T,P,N}(p, scale) where {T,P,N} = new(p, scale)
end
(::Type{ScaledPlan{T}}){T,P,N}(p::P, scale::N) = ScaledPlan{T,P,N}(p, scale)
ScaledPlan{T}(p::Plan{T}, scale::Number) = ScaledPlan{T}(p, scale)
ScaledPlan{T}(p::P, scale::N) where {T,P,N} = ScaledPlan{T,P,N}(p, scale)
ScaledPlan(p::Plan{T}, scale::Number) where T = ScaledPlan{T}(p, scale)
ScaledPlan(p::ScaledPlan, α::Number) = ScaledPlan(p.p, p.scale * α)

size(p::ScaledPlan) = size(p.p)
Expand Down
54 changes: 27 additions & 27 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,11 @@ type Dict{K,V} <: Associative{K,V}
idxfloor::Int # an index <= the indexes of all used slots
maxprobe::Int

function Dict()
function Dict{K,V}() where V where K
n = 16
new(zeros(UInt8,n), Array{K,1}(n), Array{V,1}(n), 0, 0, 0, 1, 0)
end
function Dict(kv)
h = Dict{K,V}()
for (k,v) in kv
h[k] = v
end
return h
end
Dict(p::Pair) = setindex!(Dict{K,V}(), p.second, p.first)
function Dict(ps::Pair...)
h = Dict{K,V}()
sizehint!(h, length(ps))
for p in ps
h[p.first] = p.second
end
return h
end
function Dict(d::Dict{K,V})
function Dict{K,V}(d::Dict{K,V}) where V where K
if d.ndel > 0
rehash!(d)
end
Expand All @@ -128,17 +112,33 @@ type Dict{K,V} <: Associative{K,V}
d.maxprobe)
end
end
function Dict{K,V}(kv) where V where K
h = Dict{K,V}()
for (k,v) in kv
h[k] = v
end
return h
end
Dict{K,V}(p::Pair) where V where K = setindex!(Dict{K,V}(), p.second, p.first)
function Dict{K,V}(ps::Pair...) where V where K
h = Dict{K,V}()
sizehint!(h, length(ps))
for p in ps
h[p.first] = p.second
end
return h
end
# Note the constructors of WeakKeyDict mirror these here, keep in sync.
Dict() = Dict{Any,Any}()
Dict(kv::Tuple{}) = Dict()
copy(d::Dict) = Dict(d)

const AnyDict = Dict{Any,Any}

Dict{K,V}(ps::Pair{K,V}...) = Dict{K,V}(ps)
Dict{K }(ps::Pair{K}...,) = Dict{K,Any}(ps)
Dict{V }(ps::(Pair{K,V} where K)...,) = Dict{Any,V}(ps)
Dict( ps::Pair...) = Dict{Any,Any}(ps)
Dict(ps::Pair{K,V}...) where {K,V} = Dict{K,V}(ps)
Dict(ps::Pair{K}...,) where K = Dict{K,Any}(ps)
Dict(ps::(Pair{K,V} where K)...,) where V = Dict{Any,V}(ps)
Dict(ps::Pair...) = Dict{Any,Any}(ps)

function Dict(kv)
try
Expand Down Expand Up @@ -599,9 +599,9 @@ immutable ImmutableDict{K, V} <: Associative{K,V}
parent::ImmutableDict{K, V}
key::K
value::V
ImmutableDict() = new() # represents an empty dictionary
ImmutableDict(key, value) = (empty = new(); new(empty, key, value))
ImmutableDict(parent::ImmutableDict, key, value) = new(parent, key, value)
ImmutableDict{K,V}() where {K,V} = new() # represents an empty dictionary
ImmutableDict{K,V}(key, value) where {K,V} = (empty = new(); new(empty, key, value))
ImmutableDict{K,V}(parent::ImmutableDict, key, value) where {K,V} = new(parent, key, value)
end

"""
Expand All @@ -621,8 +621,8 @@ Create a new entry in the Immutable Dictionary for the key => value pair

"""
ImmutableDict
ImmutableDict{K,V}(KV::Pair{K,V}) = ImmutableDict{K,V}(KV[1], KV[2])
ImmutableDict{K,V}(t::ImmutableDict{K,V}, KV::Pair) = ImmutableDict{K,V}(t, KV[1], KV[2])
ImmutableDict(KV::Pair{K,V}) where {K,V} = ImmutableDict{K,V}(KV[1], KV[2])
ImmutableDict(t::ImmutableDict{K,V}, KV::Pair) where {K,V} = ImmutableDict{K,V}(t, KV[1], KV[2])

function in(key_value::Pair, dict::ImmutableDict, valcmp=(==))
key, value = key_value
Expand Down
4 changes: 2 additions & 2 deletions base/fft/FFTW.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ for P in (:cFFTWPlan, :rFFTWPlan, :r2rFFTWPlan) # complex, r2c/c2r, and r2r
flags::UInt32 # planner flags
region::Any # region (iterable) of dims that are transormed
pinv::ScaledPlan
function $P(plan::PlanPtr, flags::Integer, R::Any,
X::StridedArray{T, N}, Y::StridedArray)
function $P{T,K,inplace,N}(plan::PlanPtr, flags::Integer, R::Any,
X::StridedArray{T, N}, Y::StridedArray) where {T<:fftwNumber,K,inplace,N}
p = new(plan, size(X), size(Y), strides(X), strides(Y),
alignment_of(X), alignment_of(Y), flags, R)
finalizer(p, destroy_plan)
Expand Down
2 changes: 1 addition & 1 deletion base/fft/dct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type DCTPlan{T<:fftwNumber,K,inplace} <: Plan{T}
nrm::Float64 # normalization factor
region::Dims # dimensions being transformed
pinv::DCTPlan{T}
DCTPlan(plan,r,nrm,region) = new(plan,r,nrm,region)
DCTPlan{T,K,inplace}(plan,r,nrm,region) where {T<:fftwNumber,K,inplace} = new(plan,r,nrm,region)
end

size(p::DCTPlan) = size(p.plan)
Expand Down
8 changes: 6 additions & 2 deletions base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ type AbstractIOBuffer{T<:AbstractVector{UInt8}} <: IO
ptr::Int # read (and maybe write) pointer
mark::Int # reset mark location for ptr (or <0 for no mark)

AbstractIOBuffer(data::T,readable::Bool,writable::Bool,seekable::Bool,append::Bool,maxsize::Int) =
function AbstractIOBuffer{T}(data::T, readable::Bool, writable::Bool, seekable::Bool, append::Bool,
maxsize::Int) where T<:AbstractVector{UInt8}
new(data,readable,writable,seekable,append,length(data),maxsize,1,-1)
end
end
typealias IOBuffer AbstractIOBuffer{Vector{UInt8}}

AbstractIOBuffer{T<:AbstractVector{UInt8}}(data::T, readable::Bool, writable::Bool, seekable::Bool, append::Bool, maxsize::Int) =
function AbstractIOBuffer(data::T, readable::Bool, writable::Bool, seekable::Bool, append::Bool,
maxsize::Int) where T<:AbstractVector{UInt8}
AbstractIOBuffer{T}(data, readable, writable, seekable, append, maxsize)
end

# allocate Vector{UInt8}s for IOBuffer storage that can efficiently become Strings
StringVector(n::Integer) = Vector{UInt8}(_string_n(n))
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ type SVDOperator{T<:BlasFloat,S} <: AbstractArray{T, 2}
X::S
m::Int
n::Int
SVDOperator(X::AbstractMatrix) = new(X, size(X, 1), size(X, 2))
SVDOperator{T,S}(X::AbstractMatrix) where {T<:BlasFloat,S} = new(X, size(X, 1), size(X, 2))
end

function SVDOperator{T}(A::AbstractMatrix{T})
function SVDOperator(A::AbstractMatrix{T}) where T
Tnew = typeof(zero(T)/sqrt(one(T)))
Anew = convert(AbstractMatrix{Tnew}, A)
SVDOperator{Tnew,typeof(Anew)}(Anew)
Expand Down
8 changes: 4 additions & 4 deletions base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Bidiagonal{T} <: AbstractMatrix{T}
dv::Vector{T} # diagonal
ev::Vector{T} # sub/super diagonal
isupper::Bool # is upper bidiagonal (true) or lower (false)
function Bidiagonal(dv::Vector{T}, ev::Vector{T}, isupper::Bool)
function Bidiagonal{T}(dv::Vector{T}, ev::Vector{T}, isupper::Bool) where T
if length(ev) != length(dv)-1
throw(DimensionMismatch("length of diagonal vector is $(length(dv)), length of off-diagonal vector is $(length(ev))"))
end
Expand Down Expand Up @@ -52,7 +52,7 @@ julia> Bl = Bidiagonal(dv, ev, false) # ev is on the first subdiagonal
⋅ ⋅ 9 4
```
"""
Bidiagonal{T}(dv::AbstractVector{T}, ev::AbstractVector{T}, isupper::Bool) = Bidiagonal{T}(collect(dv), collect(ev), isupper)
Bidiagonal(dv::AbstractVector{T}, ev::AbstractVector{T}, isupper::Bool) where T = Bidiagonal{T}(collect(dv), collect(ev), isupper)
Bidiagonal(dv::AbstractVector, ev::AbstractVector) = throw(ArgumentError("did you want an upper or lower Bidiagonal? Try again with an additional true (upper) or false (lower) argument."))

"""
Expand Down Expand Up @@ -106,7 +106,7 @@ Bidiagonal(dv::AbstractVector, ev::AbstractVector, uplo::Char) = begin
end
Bidiagonal(collect(dv), collect(ev), isupper)
end
function Bidiagonal{Td,Te}(dv::AbstractVector{Td}, ev::AbstractVector{Te}, isupper::Bool)
function Bidiagonal(dv::AbstractVector{Td}, ev::AbstractVector{Te}, isupper::Bool) where {Td,Te}
T = promote_type(Td,Te)
Bidiagonal(convert(Vector{T}, dv), convert(Vector{T}, ev), isupper)
end
Expand Down Expand Up @@ -197,7 +197,7 @@ full(A::Bidiagonal) = convert(Array, A)
promote_rule{T,S}(::Type{Matrix{T}}, ::Type{Bidiagonal{S}})=Matrix{promote_type(T,S)}

#Converting from Bidiagonal to Tridiagonal
Tridiagonal{T}(M::Bidiagonal{T}) = convert(Tridiagonal{T}, M)
Tridiagonal(M::Bidiagonal{T}) where T = convert(Tridiagonal{T}, M)
function convert{T}(::Type{Tridiagonal{T}}, A::Bidiagonal)
z = zeros(T, size(A)[1]-1)
A.isupper ? Tridiagonal(z, convert(Vector{T},A.dv), convert(Vector{T},A.ev)) : Tridiagonal(convert(Vector{T},A.ev), convert(Vector{T},A.dv), z)
Expand Down
12 changes: 8 additions & 4 deletions base/linalg/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
immutable Eigen{T,V,S<:AbstractMatrix,U<:AbstractVector} <: Factorization{T}
values::U
vectors::S
Eigen(values::AbstractVector{V}, vectors::AbstractMatrix{T}) = new(values, vectors)
Eigen{T,V,S,U}(values::AbstractVector{V}, vectors::AbstractMatrix{T}) where {T,V,S,U} =
new(values, vectors)
end
Eigen{T,V}(values::AbstractVector{V}, vectors::AbstractMatrix{T}) = Eigen{T,V,typeof(vectors),typeof(values)}(values, vectors)
Eigen(values::AbstractVector{V}, vectors::AbstractMatrix{T}) where {T,V} =
Eigen{T,V,typeof(vectors),typeof(values)}(values, vectors)

# Generalized eigenvalue problem.
immutable GeneralizedEigen{T,V,S<:AbstractMatrix,U<:AbstractVector} <: Factorization{T}
values::U
vectors::S
GeneralizedEigen(values::AbstractVector{V}, vectors::AbstractMatrix{T}) = new(values, vectors)
GeneralizedEigen{T,V,S,U}(values::AbstractVector{V}, vectors::AbstractMatrix{T}) where {T,V,S,U} =
new(values, vectors)
end
GeneralizedEigen{T,V}(values::AbstractVector{V}, vectors::AbstractMatrix{T}) = GeneralizedEigen{T,V,typeof(vectors),typeof(values)}(values, vectors)
GeneralizedEigen(values::AbstractVector{V}, vectors::AbstractMatrix{T}) where {T,V} =
GeneralizedEigen{T,V,typeof(vectors),typeof(values)}(values, vectors)


function getindex(A::Union{Eigen,GeneralizedEigen}, d::Symbol)
Expand Down
7 changes: 4 additions & 3 deletions base/linalg/hessenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
immutable Hessenberg{T,S<:AbstractMatrix} <: Factorization{T}
factors::S
τ::Vector{T}
Hessenberg(factors::AbstractMatrix{T}, τ::Vector{T}) = new(factors, τ)
Hessenberg{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} =
new(factors, τ)
end
Hessenberg{T}(factors::AbstractMatrix{T}, τ::Vector{T}) = Hessenberg{T,typeof(factors)}(factors, τ)
Hessenberg(factors::AbstractMatrix{T}, τ::Vector{T}) where T = Hessenberg{T,typeof(factors)}(factors, τ)

Hessenberg(A::StridedMatrix) = Hessenberg(LAPACK.gehrd!(A)...)

Expand Down Expand Up @@ -55,7 +56,7 @@ end
immutable HessenbergQ{T,S<:AbstractMatrix} <: AbstractMatrix{T}
factors::S
τ::Vector{T}
HessenbergQ(factors::AbstractMatrix{T}, τ::Vector{T}) = new(factors, τ)
HessenbergQ{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} = new(factors, τ)
end
HessenbergQ{T}(factors::AbstractMatrix{T}, τ::Vector{T}) = HessenbergQ{T,typeof(factors)}(factors, τ)
HessenbergQ(A::Hessenberg) = HessenbergQ(A.factors, A.τ)
Expand Down
8 changes: 4 additions & 4 deletions base/linalg/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
immutable LQ{T,S<:AbstractMatrix} <: Factorization{T}
factors::S
τ::Vector{T}
LQ(factors::AbstractMatrix{T}, τ::Vector{T}) = new(factors, τ)
LQ{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} = new(factors, τ)
end

immutable LQPackedQ{T,S<:AbstractMatrix} <: AbstractMatrix{T}
factors::Matrix{T}
τ::Vector{T}
LQPackedQ(factors::AbstractMatrix{T}, τ::Vector{T}) = new(factors, τ)
LQPackedQ{T,S}(factors::AbstractMatrix{T}, τ::Vector{T}) where {T,S<:AbstractMatrix} = new(factors, τ)
end

LQ{T}(factors::AbstractMatrix{T}, τ::Vector{T}) = LQ{T,typeof(factors)}(factors, τ)
LQPackedQ{T}(factors::AbstractMatrix{T}, τ::Vector{T}) = LQPackedQ{T,typeof(factors)}(factors, τ)
LQ(factors::AbstractMatrix{T}, τ::Vector{T}) where T = LQ{T,typeof(factors)}(factors, τ)
LQPackedQ(factors::AbstractMatrix{T}, τ::Vector{T}) where T = LQPackedQ{T,typeof(factors)}(factors, τ)

"""
lqfact!(A) -> LQ
Expand Down
Loading