Forums

Possibe bug with namespace and class of same name

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Possibe bug with namespace and class of same name

Postby jonathandavid » Sun Jan 18, 2009 1:42 pm

The following program fails to compile.

namespace Foo

class Bar
pass

class Foo

def main is shared
f = Bar() # LINE 9


The compiler says 'Line 9: cannot find a definition for Bar in Foo'

If I write "f = Foo.Bar()" the problem persists. But if I change the name of the namespace the problem disappears. This problem showed up when I was trying to put my Prompt class inside a Prompt namespace, so there is no obvious workaround besides changing the name of the workspace to something like PromptUtils.
jonathandavid
 
Posts: 159

Re: Possibe bug with namespace and class of same name

Postby jonathandavid » Mon Jan 19, 2009 3:00 am

One more thing. Looks like ensure blocks (postconditions) are not supported in property accessors. For example, the following does not compile:

class Foo
get bar as int
body
return 0
ensure
result == 0


The error message says basically that "ensure" was not expected there.
jonathandavid
 
Posts: 159

Re: Possibe bug with namespace and class of same name

Postby Charles » Mon Jan 19, 2009 3:36 am

I know Eiffel puts the ensure last to reflect the order of execution, but Cobra puts the body last to separate the interface from the implementation. The "body" is the implementation and everything else (test, require, ensure) is interface.

So try putting it up higher and let me know if you have any other problems. Let me know if the error message needs to be improved.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Possibe bug with namespace and class of same name

Postby jonathandavid » Mon Jan 19, 2009 4:03 am

Chuck wrote:I know Eiffel puts the ensure last to reflect the order of execution, but Cobra puts the body last to separate the interface from the implementation. The "body" is the implementation and everything else (test, require, ensure) is interface.

So try putting it up higher and let me know if you have any other problems.


Thanks, it works indeed when "ensure" is placed before "body". For some reason I was assuming that, since "invariant" could be placed anywhere inside a class, it was the same with method contracts. But you're right, I think it's better to have the interface on top and the implementation last.

Chuck wrote:Let me know if the error message needs to be improved.


The actual error message I got was:

DelegateBug.cobra(5): error: DelegateBug.cobra(5,9): error: Expecting DEDENT, but got "ensure" instead.

So yes, I guess the compiler could detect that I've written "ensure" instead of any other random symbol, and say something helpful like "ensure, test and require must be placed *before* the body of the method"
jonathandavid
 
Posts: 159


Return to Discussion

Who is online

Users browsing this forum: No registered users and 79 guests