Wiki

Ticket #304 (closed defect: fixed)

Opened 12 years ago

Last modified 12 years ago

confusing error when making a mistake in require syntax

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

Description

A better error would explain that the statement after 'require' should be on a new line

the code:

class B
	def dedentError(x as int) as char
		require x < 3
		test
			assert true
		body
			return 'z'


the output:

F:\>cobra -c -t:lib test.cobra
test.cobra(7,16): error: Expecting use, assembly, namespace, class, interface or
 enum, but got "DEDENT".
Compilation failed - 1 error, 0 warnings

Attachments

ticket-304.patch Download (4.1 KB) - added by hopscc 12 years ago.
ticket-304-2.patch Download (12.0 KB) - added by hopscc 12 years ago.

Change History

Changed 12 years ago by hopscc

Changed 12 years ago by hopscc

Better would be to fix it so that code doesnt gen an error - looks like it should pass parse OK.

Changed 12 years ago by hopscc

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

Patch so done, fixup for this case, remove some confusing and unnecesssary flag code and add a test case for parsing the common combinations of contracts, tests and method body.

Changed 12 years ago by Charles

I reviewed the patch including the test case. I wasn't planning on ever supporting this style:

    def foo(x as int) as int
        require
            x < 3
        x *= 2
        x += 1
        return x

In another words, if there is an indented section (whether require, ensure or test), then there should be a body.

Changed 12 years ago by hopscc

Well who would ever have known...

Heres another patch mandating 'body' if theres a test clause or indented contract clauses plus success and failure tests - lotsa tests indicating whats supposed to work and not.

Changed 12 years ago by hopscc

Changed 12 years ago by Charles

In this newest patch, when I look at the test cases 094 and 096, they look the same (save for minor things like spacing and name changes). Was there anything else that you wanted to test in 096? Here is a diff:

$ diff 094-parse-tests-fail.cobra 096-parse-tests-fail.cobra 
10c10
<   def dedent3a(x as int) as char
---
>   def dedent4a(x as int) as char
15c15
<       #no 'body'
---
>       #no body
22c22
<       assert c.dedent3a(2) == c'z'
---
>       assert c.dedent4a(2) == c'z'

Changed 12 years ago by Charles

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

Applied in changeset:2893. Thanks to both of you.

Note: See TracTickets for help on using tickets.