Skip to content

Commit

Permalink
Inform {} planned change from 0.3 to 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyhffong committed Oct 5, 2014
1 parent 9aaa480 commit ab8a922
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/Lint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ function lintexpr( ex::Any, ctx::LintContext )
linthcat( ex, ctx )
elseif ex.head == :typed_hcat
linttyped_hcat( ex, ctx )
elseif ex.head == :cell1d
lintcell1d( ex, ctx )
elseif ex.head == :while
lintwhile( ex, ctx )
elseif ex.head == :for
Expand Down
2 changes: 1 addition & 1 deletion src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function lintfunction( ex::Expr, ctx::LintContext; ctorType = symbol( "" ) )
return
end

temporaryTypes = {}
temporaryTypes = Any[]
fname = symbol("")
if ex.args[1].head == :tuple # anonymous
# do nothing
Expand Down
2 changes: 1 addition & 1 deletion src/knowndeprec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function getFuncNameAndSig( callex::Expr, strict::Bool=true )
return ( nothing, nothing )
end
end
sig = {}
sig = Any[]
for i in 2:length( callex.args )
sube = callex.args[i]
if Meta.isexpr( sube, :parameters )
Expand Down
18 changes: 14 additions & 4 deletions src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ function lintdict( ex::Expr, ctx::LintContext; typed::Bool = false )
# :Any=>:Any, not TopNode( :Any )=>TopNode( :Any )
declktype = ex.args[1].args[1]
declvtype = ex.args[1].args[2]
if declktype == TopNode( :Any ) && declvtype == TopNode( :Any ) &&
!in( Any, ktypes ) && length( ktypes ) == 1 &&
!in( Any, vtypes ) && length( vtypes ) == 1
msg( ctx, 0, "There is only 1 key type && 1 value type. Use [] for better performances.")
if declktype == TopNode( :Any ) && declvtype == TopNode( :Any )
msg( ctx, 0, "Untyped dictionary {a=>b,...}, may be deprecated by Julia 0.4. Use (Any=>Any)[a=>b,...].")
if !in( Any, ktypes ) && length( ktypes ) == 1 && !in( Any, vtypes ) && length( vtypes ) == 1
msg( ctx, 0, "There is only 1 key type && 1 value type. Use explicit (K=>V)[] for better performances.")
end
end
end
end
Expand Down Expand Up @@ -95,3 +96,12 @@ function linttyped_hcat( ex::Expr, ctx::LintContext )
lintexpr( a, ctx )
end
end

function lintcell1d( ex::Expr, ctx::LintContext )
if length( ex.args ) == 0 && VERSION < v"0.4-"
msg( ctx, 0, "Using {} for Any[] may be deprecated in Julia 0.4" )
end
for a in ex.args
lintexpr( a, ctx )
end
end
4 changes: 2 additions & 2 deletions src/modules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function lintusing( ex::Expr, ctx::LintContext )
end
for s in ex.args
if s != :(.)
ctx.callstack[end].declglobs[ s ] = { :file => ctx.file, :line => ctx.line }
ctx.callstack[end].declglobs[ s ] = (Symbol=>Any)[ :file => ctx.file, :line => ctx.line ]
end
end
if ex.args[1] != :(.)
Expand All @@ -43,7 +43,7 @@ function lintusing( ex::Expr, ctx::LintContext )
if t == Module
for n in names( m )
if !haskey( ctx.callstack[end].declglobs, n )
ctx.callstack[end].declglobs[ n ] = { :file => ctx.file, :line => ctx.line }
ctx.callstack[end].declglobs[ n ] = (Symbol=>Any)[ :file => ctx.file, :line => ctx.line ]
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function registersymboluse( sym::Symbol, ctx::LintContext )
end
found = (t == Function)
if found
ctx.callstack[end].declglobs[ sym ] = { :file => ctx.file, :line => ctx.line }
ctx.callstack[end].declglobs[ sym ] = (Symbol=>Any)[ :file => ctx.file, :line => ctx.line ]
end
end

Expand All @@ -106,7 +106,7 @@ function lintglobal( ex::Expr, ctx::LintContext )
for sym in ex.args
if typeof(sym) == Symbol
if !haskey( ctx.callstack[end].declglobs, sym)
ctx.callstack[end].declglobs[ sym ] = { :file=>ctx.file, :line=>ctx.line }
ctx.callstack[end].declglobs[ sym ] = (Symbol=>Any)[ :file=>ctx.file, :line=>ctx.line ]
end
elseif isexpr( sym, ASSIGN_OPS )
lintassignment( sym, ctx; isGlobal=true )
Expand Down Expand Up @@ -279,7 +279,7 @@ function lintassignment( ex::Expr, ctx::LintContext; islocal = false, isConst=fa
end
end
if isGlobal || isConst || (ctx.functionLvl + ctx.macroLvl == 0 && ctx.callstack[end].isTop)
ctx.callstack[end].declglobs[ s ] = { :file => ctx.file, :line => ctx.line }
ctx.callstack[end].declglobs[ s ] = (Symbol=>Any)[ :file => ctx.file, :line => ctx.line ]
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions test/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,10 @@ sndlast = s[end -1]
"""
msgs = lintstr( s )
@test( contains( msgs[1].message, "Ambiguity of `[end -n]` as a matrix row vs index [end-n]" ) )
s = """
s = {}
"""
msgs = lintstr( s )
if VERSION < v"0.4-"
@test( contains( msgs[1].message, "Using {} for Any[] may be deprecated in Julia 0.4" ) )
end
14 changes: 12 additions & 2 deletions test/dictkey.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,24 @@ s = """
msgs = lintstr( s )

@test( contains( msgs[1].message, "Duplicate key" ) )
@test( contains( msgs[2].message, "Use [] for better performances" ) )
if VERSION < v"0.4-"
@test( contains( msgs[2].message, "Untyped dictionary {a=>b,...}, may be deprecated by Julia 0.4" ) )
@test( contains( msgs[3].message, "Use explicit (K=>V)[] for better performances" ) )
else
@test( contains( msgs[2].message, "Use explicit (K=>V)[] for better performances" ) )
end

s = """
{ :a=>Date( 2014,1,1 ), :b=>Date( 2015,1,1 ) }
"""
msgs = lintstr( s )

@test( contains( msgs[1].message, "Use [] for better performances" ) )
if VERSION < v"0.4-"
@test( contains( msgs[1].message, "Untyped dictionary {a=>b,...}, may be deprecated by Julia 0.4" ) )
@test( contains( msgs[2].message, "Use explicit (K=>V)[] for better performances" ) )
else
@test( contains( msgs[1].message, "Use explicit (K=>V)[] for better performances" ) )
end

s = """
[ :a=>1, :b=>"" ]
Expand Down

1 comment on commit ab8a922

@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.

Related Julia change: JuliaLang/julia#8578 (comment)

Please sign in to comment.