Wiki

Ticket #238 (closed defect: fixed)

Opened 14 years ago

Last modified 14 years ago

Bad Code gen for structs containing Strings

Reported by: hopscc Owned by: Chuck
Priority: medium Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

struct St
	var name as String
	var n as int
	
	cue init(name as String, n as int)
		.name = name
		.n = n
class T
	def main is shared
		x = St('xxx', 10)

gives

c:\home\hops\src\cobra\Tst\struct.cobra(2): error: "St.Name": cannot have instance field initializers in structs (C#)
Compilation failed - 1 error, 0 warnings

(Error from C# compiler)
offending lines in gen C# source

#line 1
public struct St{
#line 1
	
#line 1
	int _ih_invariantGuard;
#line 1
	
#line 2
	public System.String Name = null;
#line 3
	public System.Int32 N;
#line 3
} // struct St

Same for any ref class not just Strings.

Looks like for code gen in structs explicit (Null) initialisation of refclass members should be elided

Attachments

struct-init.patch Download (2.6 KB) - added by hopscc 14 years ago.

Change History

Changed 14 years ago by hopscc

Changed 14 years ago by hopscc

  • status changed from new to assigned
  • owner set to Chuck

Codepatch, new test and relnote for suppressing default init on vars in structs.

Changed 14 years ago by Chuck

  • status changed from assigned to closed
  • resolution set to fixed

Patch applied in changeset:2420
Thanks.

Note: See TracTickets for help on using tickets.