From 9aaa480e088acfb6c29f8ff036552a4ba437067d Mon Sep 17 00:00:00 2001 From: Tony Fong Date: Fri, 3 Oct 2014 17:05:17 +0700 Subject: [PATCH] add lintpragma for short new argument case --- src/functions.jl | 4 +++- test/type.jl | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/functions.jl b/src/functions.jl index 0e6c664..8acd036 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -360,7 +360,9 @@ function lintfunctioncall( ex::Expr, ctx::LintContext ) if haskey( ctx.callstack[i].typefields, tname ) fields = ctx.callstack[i].typefields[ tname ] if 0 < length( ex.args ) - 1 < length( fields ) - msg( ctx, 0, "new is provided with fewer arguments than fields." ) + if !in( "Ignore short new argument", ctx.callstack[end].pragmas ) + msg( ctx, 0, "new is provided with fewer arguments than fields." ) + end elseif length( fields ) < length( ex.args ) - 1 msg( ctx, 2, "new is provided with more arguments than fields" ) end diff --git a/test/type.jl b/test/type.jl index 907e72d..622e267 100644 --- a/test/type.jl +++ b/test/type.jl @@ -223,3 +223,15 @@ end """ msgs = lintstr(s) @assert( isempty( msgs ) ) # ok +s = """ +type MyType + a::Int + b::Int + function MyType( x ) + @lintpragma( "Ignore short new argument" ) + new(x) + end +end +""" +msgs = lintstr(s) +@assert( isempty( msgs ) )