Wiki

Ticket #165 (closed defect: fixed)

Opened 8 years ago

Last modified 8 years ago

Bad error message for bad numeric for loop

Reported by: Chuck Owned by: eric.sellon
Priority: major Milestone: Cobra 0.9
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

In the following code, the upper bound of the loop is j/2 although j//2 was probably the true intent:

class X
	def main
		j = 4
		for i in 0 : j/2
			print i * 2   

The error message is really bad:

error: For arg 1: Cannot apply STAR to Object and int. Try finding a method that performs this function.

Looks like numeric for loops need to check that both bounds are integer types.

Attachments

ticket165.patch Download (1.9 KB) - added by eric.sellon 8 years ago.

Change History

Changed 8 years ago by eric.sellon

  • owner set to eric.sellon
  • status changed from new to assigned

Changed 8 years ago by eric.sellon

This patch should do the trick.

Changed 8 years ago by eric.sellon

Changed 8 years ago by Chuck

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

Thanks. Some feedback and notes:

  • This all came up because someone wrote for i in j : k/2. So I added some extra help for that case informing the user about the "//" operator.
  • The .error. in the test said "The for loop", but the error message starts out with "For loop ..." so the test failed. Try to do a final test run after any mods to the compiler implementation.
  • Also the error messages said "start condition", "stop condition", etc. I changed these to "expression" as in "start expression" since it's not really a condition.
  • When error messages mention types by name, double quotes are put around them to make them standout. It's just a convention followed in the other error messages. Like: The type "int" ...
  • In _bindImp, As a precaution, I added checks like if not _start.hasError .... Generally if those expressions have errors, it won't be worth it to do further checking on them.
  • In _bindImp, I moved the "optimization" part of _bindImp after the new error checking, since it makes no sense to work on optimizations until error checking is successful. Hmmm, maybe that should be a new phase!
  • Very minor, but in _checkCompatibleTypes, the target statement of each if is a return so I don't bother with else if.
  • Also, very minor, in the same method I put if type1 == type2 first since it is the most common case. Might as well exit early.
  • You can review changeset:2173 to see the final changes.
Note: See TracTickets for help on using tickets.