Constructor with multiple parametric arguments

Hi, I encounter a bizzare behaviour for an inner constructor of a struct, and I am trying to understand what is happening. The first attempt was the following

struct Log_Float{T <: Integer, S <: Number}
    sign::T    ##sign of the number
    val::S     ##value of the log
    
    ##INNER CONSTRUCTOR
    function Log_Float{T,S}(x::T, y::S)  where T<:Integer where S<:Number
        !(x in [-1, 1]) && throw(ArgumentError("Sign has to be ether plus or minus 1")) 
        return new(x, y)
    end
    
end

But declaring in this form, and proceding by creating a Log_Float, I get the following error message:

ERROR: StackOverflowError:
Stacktrace:
 [1] Main.Log_Floats.Log_Float(::Int64, ::Int64) at C:\Users\lucas\Desktop\Log_Floats.jl:17 (repeats 79984 times)

I tried different hands on way to solve this problem, as I created Structs with just one single parametric argument following the above structure many times, without having any problem (it’s the structure indicated on the Julia documentation). To solve the problem I had to write:

struct Log_Float{T <: Integer, S <: Number}
    sign::T    ##sign of the number
    val::S     ##value of the log
    
    ##INNER CONSTRUCTOR
    function Log_Float(x::T, y::S)  where T<:Integer where S<:Number
        !(x in [-1, 1]) && throw(ArgumentError("Sign has to be ether plus or minus 1")) 
        return new{T,S}(x, y)
    end
    
end

Any idea of what was the original problem, and why the second version solves the problem?

In the first case, you have recursion in the outer constructor Log_Float(x, y).
In the second case, the inner constructor method takes precedence for the recursive call.

Without seeing the outer constructor code for the first case, it’s impossible to say what exactly is wrong.

First of all, thanks for the quick answer. The code for the outer constructor in the first case was:

##OUTER CONSTRUCTORS
Log_Float(x::T, y::S) where T<:Number where S<:Number = Log_Float(convert(Int64,x), y)
Log_Float(number::S) where S<:Number = Log_Float(sign(number), log(abs(number)))
Log_Float(x::T, y::S) where T<:Number where S<:Number = Log_Float(convert(Int64,x), y)

Which method do you think it’s calling for the rhp?

I think the right hand part should call the inner constructor. At least from my understanding.

There is no inner constructor Log_Float(x, y), only Log_Float{T,S}(x, y).

Ok I see! Thank you a lot!