Wiki

Changeset 2298

Show
Ignore:
Timestamp:
03/03/10 06:00:51 (2 years ago)
Author:
Chuck.Esterbrook
Message:

When using attribute "Foo", look for "FooAttribute?" first. This reduces collisions of symbols.

Location:
cobra/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/Attributes.cobra

    r2262 r2298  
    4646            _expr.left.bindImp  # Could cause a transformation. Handled in .replaceChild 
    4747            name = _expr.dotRight.name 
    48             defi = _expr.left.definition.memberForName(name) 
    49             if defi is nil 
     48            if not name.endsWith('Attribute') 
    5049                defi = _expr.left.definition.memberForName(name+'Attribute') 
    5150            if defi is nil 
    52                 _expr.throwCannotFindMemberError(_expr.left, '[name] or [name]Attribute') 
     51                defi = _expr.left.definition.memberForName(name) 
     52            if defi is nil 
     53                _expr.throwCannotFindMemberError(_expr.left, '[name]Attribute or [name]') 
    5354            if defi inherits IType 
    54                 _expr = PostCallExpr(_expr.right.token, TypeExpr(_expr.right.token, defi), _expr.dotRight.args, isForAttribute=true) 
     55                _expr = PostCallExpr(_expr.right.token, TypeExpr(_expr.right.token, defi), _expr.dotRight.args) 
    5556            else 
    5657                .throwError('Expecting an attribute class instead of a [defi.englishName].') 
    5758        else if _expr inherits PostCallExpr 
    5859            name = _expr.name 
    59             if not name.endsWith('Attribute') and name.canBeUndottedMemberName and not .compiler.symbolForName(name, false) 
     60            if not name.endsWith('Attribute') and name.canBeUndottedMemberName 
    6061                if .compiler.symbolForName(name+'Attribute', false) 
    61                     _expr = PostCallExpr(_expr.token, IdentifierExpr(_expr.token, name+'Attribute'), _expr.args, isForAttribute=true) 
    62             else 
    63                 _expr.isForAttribute = true 
     62                    _expr = PostCallExpr(_expr.token, IdentifierExpr(_expr.token, name+'Attribute'), _expr.args) 
    6463        assert _expr inherits PostCallExpr 
     64        (_expr to PostCallExpr).isForAttribute = true 
    6565        _expr.bindImp 
    6666 
  • cobra/trunk/Tests/320-misc-two/800-attributes/100-attributes.cobra

    r2160 r2298  
    251251 
    252252    pass 
     253 
     254 
     255class TestAttribute inherits Attribute 
     256 
     257    pass 
     258 
     259 
     260class UseTestAttribute 
     261 
     262    def foo has Test  # `Test` is also a namespace in Cobra.Lang, but the attribute "TestAttribute" takes precedence 
     263        pass