bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 13 forks source link

Structs: Nested New() differs to types #599

Open GWRon opened 1 year ago

GWRon commented 1 year ago
SuperStrict
Framework Brl.StandardIO

Struct STest
  Field ReadOnly X:Int
  Field ReadOnly Y:Int

    Method New(value:Int)
        New(value, value)
    End Method

    Method New(value1:Int, value2:Int)
        Self.X = value1
        Self.Y = value2
    End Method
End Struct 

Local s:STest = New STest(10, 20)
Print s.X+", "+ s.Y '10, 20

Local s2:STest = New STest(10)
Print s2.X+", "+ s2.Y '0, 0

Output:

10, 20
0, 0

Now change the struct to be a type:

SuperStrict
Framework Brl.StandardIO

Type STest
  Field ReadOnly X:Int
  Field ReadOnly Y:Int

    Method New(value:Int)
        New(value, value)
    End Method

    Method New(value1:Int, value2:Int)
        Self.X = value1
        Self.Y = value2
    End Method
End Type 

Local s:STest = New STest(10, 20)
Print s.X+", "+ s.Y '10, 20

Local s2:STest = New STest(10)
Print s2.X+", "+ s2.Y '0,0

And the output becomes:

10, 20
10, 10

I would have thought, that both should have the same output

GWRon commented 1 year ago

Seems for Type it calls the overloaded new(value1,value2), while for Struct this does not happen:

type:

void __m_untitled1_STest_New_i(struct _m_untitled1_STest_obj* o,BBINT bbt_value) {
    __m_untitled1_STest_New_ii((struct _m_untitled1_STest_obj*)o,bbt_value,bbt_value);
    o->clas = &_m_untitled1_STest;
    #line 9 "/home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled1.bmx"
}

Struct

void __m_untitled2_STest_New_i(struct _m_untitled2_STest* o,BBINT bbt_value) {
    #line 9 "/home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled2.bmx"
}