Wiki

Ticket #198 (closed defect: fixed)

Opened 15 years ago

Last modified 15 years ago

"error: Use of unassigned local variable" when using value types

Reported by: gauthier Owned by: Chuck
Priority: major Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

class Program
	def main
		ensure
			enddate > begindate
		body
			begindate = DateTime.now.date
			enddate = begindate.addDays(1)

gives

c:\tmp\cobratickets\tmp.cobra(3): error: Use of unassigned local variable "enddate"
c:\tmp\cobratickets\tmp.cobra(3): error: Use of unassigned local variable "begindate"
Compilation failed - 2 errors, 0 warnings
Not running due to errors above.

Looking at intermediate .cs code, I think this may be reproducible only with value types.

Change History

Changed 15 years ago by Chuck

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

Well actually you should not have an "ensure" referring to local variables since contracts are part of the public interface of a method. Use an "assert" within the body of the method if you want to verify intermediate steps of your method.

I'll add a check for this.

Changed 15 years ago by Chuck

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

I have added the error checking in changeset:2319

Note: See TracTickets for help on using tickets.