diff --git a/src/controls.jl b/src/controls.jl index 0bf1227..7d34669 100644 --- a/src/controls.jl +++ b/src/controls.jl @@ -94,6 +94,24 @@ function lintcomprehension( ex::Expr, ctx::LintContext; typed::Bool = false ) pushVarScope( ctx ) st = typed? 3 :2 fn = typed? 2 :1 + + if typed + if ex.head == :typed_dict_comprehension + if isexpr( ex.args[1], :(=>) ) + declktype = ex.args[1].args[1] + declvtype = ex.args[1].args[2] + if declktype == TopNode( :Any ) && declvtype == TopNode( :Any ) && VERSION < v"0.4-" + msg( ctx, 0, "Untyped dictionary {a=>b for (a,b) in c}, may be deprecated by Julia 0.4. Use (Any=>Any)[a=>b for (a,b) in c].") + end + end + else + declvtype = ex.args[1] + if declvtype == TopNode( :Any ) && VERSION < v"0.4-" + msg( ctx, 0, "Untyped dictionary {a for a in c}, may be deprecated by Julia 0.4. Use (Any)[a for a in c].") + end + end + end + for i in st:length(ex.args) if isexpr( ex.args[i], :(=) ) lintassignment( ex.args[i], ctx; islocal=true, isForLoop=true ) # note contrast with for loop diff --git a/test/comprehensions.jl b/test/comprehensions.jl index ac9be6d..6eb02e6 100644 --- a/test/comprehensions.jl +++ b/test/comprehensions.jl @@ -3,6 +3,15 @@ s = """[i for i in 1:2] msgs = lintstr( s ) @assert( isempty( msgs ) ) +s = """{i for i in 1:2} +""" +msgs = lintstr( s ) +if VERSION < v"0.4-" + @assert( contains( msgs[1].message, "deprecated by Julia 0.4" ) ) +else + @assert( isempty( msgs ) ) +end + s = """ [j => j*j for j in 1:2 ] """ @@ -13,7 +22,11 @@ s = """ { y1 => y1*y1 for y1 in 1:2 } """ msgs = lintstr( s ) -@assert( isempty( msgs ) ) +if VERSION < v"0.4-" + @assert( contains( msgs[1].message, "deprecated by Julia 0.4" ) ) +else + @assert( isempty( msgs ) ) +end s = """ (Int=>Int)[ y2 => y2*y2 for y2 in 1:2 ]