Archived

This forum has been archived. Please start a new discussion on GitHub.

Duplicate naming error while running slice2java

I would appreciate your help in understanding why this is not supported or what am I doing wrong.

Thanks

My sample ice file is
[COLOR="Blue"]#ifndef TEST_ICE
#define TEST_ICE

module com
{
    module xxx
    {
        module data
        {
            module testsomething
            {
                module service
                {
                    interface TestSomething
                    {
                        int         getPoints();
                    };
    
                    interface TestSomethingHandler
                    {
                        TestSomething* getSomething(string name );
                    };
                };
            };
        };
    };
};

#endif

[/COLOR]

When I run slice2java I get following error

slice2java --output-dir c:\myproj\src c:\myproj\ice\test.ice
c:\\myproj\\ice\\test.ice:16: interface name `testsomething' cannot differ only in capitalization from enclosing module `testsomething' (first defined at c:\\myproj\\ice\\test.ice:11)
c:\\myproj\\ice\\test.ice:22: module name `TestSomething' is capitalized inconsistently with its previous name: `::com::xxx::data::testsomething'
c:\\myproj\\ice\\test.ice:22: `TestSomething' is not a type

Comments

  • mes
    mes California
    Hi,

    When you declared the module testsomething, you introduced that symbol into the enclosing scope. Slice does not permit you to introduce another symbol that differs only in capitalization (such as TestSomething) into the same scope, or into any nested scope. You'll need to rename the module or the interface.

    Take care,
    - Mark
  • By the way, initially, the rule what as that only immediately nested scopes could not have the same name because that can cause problems with constructors in many languages.

    Later, we made the rule more strict to prohibit scopes with the same name anywhere along the nesting chain because of C#: prior to C# 2.0, there was no way to anchor a symbol lookup at the global scope so, if you had nested scopes with the same name, anything outside the inner scope became inaccessible from within the inner scope.

    If we ever get to the point where we drop support for C# 1.0, we can relax this rule again. However, as a general point, I would still discourage having nested scopes with the same name as a matter of style--the potential for confusion this creates is almost certainly worse than having to use unique names for nested scopes.

    Cheers,

    Michi.
  • Gentlemen,

    Thanks for the update and explaining me the reasoning behind the situation.

    Regarcs