Forums

Namespace clarifications

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

Namespace clarifications

Postby Charles » Tue Jan 13, 2009 4:20 am

Due to some recent bug reports that came straight to me, I have cleaned up some of the behavior around namespaces and the "use" directive.

First, Cobra had the weird property that if you wrote "use A.B.C" it also implied "use A.B" and "use A". In other words, Cobra would follow the namespace parent chain. I don't know why that was there in the first place, but it could lead to some strange results in complex programs with many "use" directives. Sometimes you only want what's in "A.B.C" and not in the parents.

Second, Cobra can now give this error:
Code: Select all
Ambiguous reference "Foo" found in namespaces "A" and "B".

In other words, if you use a class Foo and there are two different Foo's visible given the "use" directives, you must resolve the ambiguity with qualification (such as A.Foo or B.Foo). Previously, Cobra would just pick the first one which could be a source of confusion. Also, that meant that the order of "use" directives mattered. Now it does not.

Third, Cobra was relying on the C# "using" statement in generated code and also referencing its own types (such as RequireException, AssertException, etc.) without qualification. That was a time bomb waiting to go off. All types are now fully qualified in the generated code which eliminates the possibility of surprises.

I had to tweak just a few test cases and a few lines of code in the compiler. So the pain here is small. The improvement in avoiding pain from ambiguity and strange errors is huge.

All regression test cases pass. But if you have any problems let me know.

Some reminders:

-- These "use" directives are implied in every Cobra file:
use System
use System.Collections.Generic
use System.IO
use System.Text
use Cobra.Lang

(I'm undecided if System.Collections should be included. Feel free to muse.)

-- Generics are considered to have a name that incorporates the number of generic arguments. So "X", "X<of>" and "X<of,>" are three different types with no naming conflict (same as C#).
Charles
 
Posts: 2510
Location: Los Angeles, CA

Re: Namespace clarifications

Postby pchapin » Wed Jan 14, 2009 5:42 am

These changes/fixes sound great to me... a nice clean up. Thanks!
pchapin
 
Posts: 46
Location: Vermont, USA

Re: Namespace clarifications

Postby Charles » Wed Jan 14, 2009 7:11 pm

You're welcome.
Charles
 
Posts: 2510
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron