Warnings about unused parameter in method

So I have a declaration as below

abstract type C end
struct A <:C
       x::Float64
       y::Float64
end
function pattern(ant::A, pos::Float64)
return pos^2
end

struct B <: C
       x::Float64
       y::Float64
       z::Float64
end
function pattern(ant::B, pos::Float64)
return B.z*pos^2
end

and the warning generated is that ant is unused in the first pattern method-- this is logical because that is the case. However, the object is being passed into the function to differentiate it from application of the pattern function to another object, where the object is relevant – multiple dispatch at work. I don’t suppose there is any way of suppressing the compiler warning for this instance, is there? Its probably not a big deal.

/K

I’d probably write that as:

function pattern(::A, pos::Float64)
  pos^2
end

which hopefully makes it clear to the reader (and to whatever tool is generating the warning) that the first argument’s value is unused but its type is relevant.

2 Likes

That worked like magic./K