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

ERROR new is not provided with the correct number of arguments #38

Closed
lendle opened this issue Oct 3, 2014 · 4 comments
Closed

ERROR new is not provided with the correct number of arguments #38

lendle opened this issue Oct 3, 2014 · 4 comments

Comments

@lendle
Copy link

lendle commented Oct 3, 2014

I'm calling new() without args in an inner constructor to avoid allocating/defining some fields until later. This causes Lint to announce an error. As far as I know this is the only way to do not define all fields when constructing a type.

I'm not really sure what Lint should do here, but I think it is not necessarily wrong to use new() without args. Thoughts?

lintstr("type A  x::Vector ; A() = new() end")
1-element Array{LintMessage,1}:
                 none [A                   ]    3 ERROR  new is not provided with the correct number of arguments
@tonyhffong
Copy link
Owner

Yes, I missed that. How about this?

  • nargs = 0. No warning
  • 0 < nargs < nfields. Lint Warning (I do want to catch fat finger cases)
  • nargs > nfields. Lint Error (as it is now)

@tonyhffong
Copy link
Owner

Also, if you do something like this:

type MyType
    a::Int
    b::Int
    function MyType( x )
        @lintpragma( "Ignore short new argument" )
        new(x)
    end
end

It would suppress warnings as well.

@lendle
Copy link
Author

lendle commented Oct 3, 2014

I was thinking something along the lines of nargs=0 -> no warning.

@tonyhffong
Copy link
Owner

Yes, that's exactly the change I've made. The test case:

s = """
type MyType
    a::Int
    b::Int
    MyType()= new()
end
"""
msgs = lintstr(s)
@assert( isempty( msgs ) ) # ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants