Skip to content

Commit

Permalink
Inform comprehension {} deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyhffong committed Oct 7, 2014
1 parent f819bd3 commit 94a1b1e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/controls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion test/comprehensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
"""
Expand All @@ -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 ]
Expand Down

1 comment on commit 94a1b1e

@tonyhffong
Copy link
Owner Author

Choose a reason for hiding this comment

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

Please sign in to comment.