Page 1 of 1

Possibe bug with namespace and class of same name

PostPosted: Sun Jan 18, 2009 1:42 pm
by jonathandavid
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.

Re: Possibe bug with namespace and class of same name

PostPosted: Mon Jan 19, 2009 3:00 am
by jonathandavid
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.

Re: Possibe bug with namespace and class of same name

PostPosted: Mon Jan 19, 2009 3:36 am
by Charles
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.

Re: Possibe bug with namespace and class of same name

PostPosted: Mon Jan 19, 2009 4:03 am
by jonathandavid
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"