bcc icon indicating copy to clipboard operation
bcc copied to clipboard

Structs: Nested New() differs to types

Open GWRon opened this issue 2 years ago • 1 comments

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 avatar Oct 17 '22 21:10 GWRon