Boo

Name resolution fails if a type in the current namespace has the same name as one in an imported namespace

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 0.7.5
  • Fix Version/s: 0.8.1
  • Component/s: None
  • Labels:
    None
  • Environment:
    .NET 2.0 RTM
  • Number of attachments :
    0

Description

namespace Alpha

class Foo:
....pass

interface INeeded:
....pass

namespace Bravo:

import Alpha

class Foo:
....pass

class Bar(Foo, INeeded):
....pass

Error: Type 'Foo' is invalid. <--- NOTICE that it does not say 'Ambiguous reference'.
The fix is to specify the Full name of the type: Bravo.Foo, but when you got Boo.Lang.Useful.Pipelines.Documentation.Ast.Node, it's horrible.
BOO should look and resolve types in the current namespace before it looks in other namespaces.

Activity

Hide
Cameron Kenneth Knight added a comment -

The test above doesn't cut it:

// File: Alpha.boo
namespace Alpha

class Foo:
pass

interface INeeded:
pass

// File: BravoAlternate.boo
namespace Bravo:

class Foo:
pass

// File: Bravo.boo
namespace Bravo

import Alpha

class Bar(Foo, INeeded):
pass

Show
Cameron Kenneth Knight added a comment - The test above doesn't cut it: // File: Alpha.boo namespace Alpha class Foo: pass interface INeeded: pass // File: BravoAlternate.boo namespace Bravo: class Foo: pass // File: Bravo.boo namespace Bravo import Alpha class Bar(Foo, INeeded): pass
Hide
Doug H added a comment -

One way to temporarily fix this, in src/boo.lang.compiler/typesystem/nameresolutionservice.cs in the ResolveSimpleTypeReference method.

At the line that says:
if (null == info || EntityType.Type != info.EntityType)

Add this BEFORE that line:

if (null != info && EntityType.Ambiguous == info.EntityType)

{ IEntity[] entities = ((Ambiguous)info).Entities; info = entities[entities.Length-1]; node.Name = info.FullName; }

I also added an overload of the ResolveQualifiedName method that takes an entitytype, but that is not called in this particular test.
I changed:
info = ResolveQualifiedName(node.Name);
to
info = ResolveQualifiedName(node.Name, EntityType.Type);
and that overloaded method looks like:
public IEntity ResolveQualifiedName(string name, EntityType flags)

{ _buffer.Clear(); ResolveQualifiedName(_buffer, name, flags); return GetEntityFromBuffer(); }
Show
Doug H added a comment - One way to temporarily fix this, in src/boo.lang.compiler/typesystem/nameresolutionservice.cs in the ResolveSimpleTypeReference method. At the line that says: if (null == info || EntityType.Type != info.EntityType) Add this BEFORE that line: if (null != info && EntityType.Ambiguous == info.EntityType) { IEntity[] entities = ((Ambiguous)info).Entities; info = entities[entities.Length-1]; node.Name = info.FullName; } I also added an overload of the ResolveQualifiedName method that takes an entitytype, but that is not called in this particular test. I changed: info = ResolveQualifiedName(node.Name); to info = ResolveQualifiedName(node.Name, EntityType.Type); and that overloaded method looks like: public IEntity ResolveQualifiedName(string name, EntityType flags) { _buffer.Clear(); ResolveQualifiedName(_buffer, name, flags); return GetEntityFromBuffer(); }
Hide
Doug H added a comment -

Also, I'm just guessing, but if you want to create and use classes with the same names and namespaces as those in boo.lang.compiler or other automatically referenced assemblies, you could have outside assemblies inserted at the beginning of the list instead of adding them to the end.
Change this in the sources for booc, booi, and the initializenameresolutionservices step:
Parameters.References.Add(asm);
to Parameters.References.Insert(0, asm) or whatever

Show
Doug H added a comment - Also, I'm just guessing, but if you want to create and use classes with the same names and namespaces as those in boo.lang.compiler or other automatically referenced assemblies, you could have outside assemblies inserted at the beginning of the list instead of adding them to the end. Change this in the sources for booc, booi, and the initializenameresolutionservices step: Parameters.References.Add(asm); to Parameters.References.Insert(0, asm) or whatever
Hide
Cedric Vivier added a comment -

Correctly outputs "Ambiguous reference" since 0.8.1

Show
Cedric Vivier added a comment - Correctly outputs "Ambiguous reference" since 0.8.1

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: