Changeset 1729

Show
Ignore:
Timestamp:
11/04/08 20:00:30 (2 months ago)
Author:
Chuck.Esterbrook
Message:

Fixed: Invoking _someMethod without parens in an if statement or other expression causes a false compilation error.
reported-by: hopscc

Location:
cobra/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Developer/IntermediateReleaseNotes.text

    r1728 r1729  
    199199 
    200200* Fixed: Assigning values less than zero to variables of type int8 and int16 gives a false compilation error. ticket:45 
     201 
     202* Fixed: Invoking _someMethod without parens in an `if` statement or other expression causes a false compilation error. 
  • cobra/trunk/Source/BinaryOpExpr.cobra

    r1717 r1729  
    601601                        .compiler.curCodeMember.usesBase  # use of base implies override if the containing member is not already marked new 
    602602                else if _left inherits ThisLit 
    603                         if _left.isExplicit  # CC: combine above 
     603                        if _left.isVisible 
    604604                                .compiler.warning(this, 'An explicit "this" literal is unnecessary for accessing members of the current object. You can remove "this".') 
    605                         else if _right inherits MemberExpr 
    606                                 if _right.name.startsWith('_') 
    607                                         .compiler.warning(this, 'An explicit dot (".") is unnecessary for accessing underscored members of the current object. You can remove ".".') 
     605                        else if .isVisible and .dotRight.name.startsWith('_') 
     606                                .compiler.warning(this, 'An explicit dot (".") is unnecessary for accessing underscored members of the current object. You can remove ".".') 
    608607                if not _type 
    609608                        assert _right.type 
  • cobra/trunk/Source/CobraParser.cobra

    r1728 r1729  
    26712671                        finally 
    26722672                                .opStack.pop 
    2673                         return BinaryOpExpr.make(token to !, 'DOT', ThisLit(token), expr) 
     2673                        return BinaryOpExpr.make(token to !, 'DOT', ThisLit(token, isVisible=false), expr) 
    26742674                else if peek=='NIL' 
    26752675                        return NilLiteral(.grab) 
  • cobra/trunk/Source/Expr.cobra

    r1717 r1729  
    4848        var _contextType as IType? 
    4949        var _isParened as bool 
     50        var _isVisible as bool 
    5051        var _argumentLabel = ArgumentLabel.None 
    5152 
    5253        def init(token as IToken) 
    5354                base.init(token) 
     55                _isVisible = true 
    5456 
    5557        def addRefFields is override 
     
    6062                """ 
    6163                Indicates the label for an argument such as 'out' or 'inout'. 
     64                """ 
     65 
     66        pro isVisible from var 
     67                """ 
     68                Indicates if the expression is visible in the source code. 
     69                Defaults to true. 
     70                 
     71                An expression may not be if it was generated by means other than parsing, 
     72                usually during _bindImp for the purpose of a _transformTo call. 
     73                It's not always imperative to set this to false--only in cases where it's needed. 
     74                Those cases are typically warnings centered around coding style ("favor succinct forms"). 
    6275                """ 
    6376 
     
    871884                if _type is nil 
    872885                        if _definition 
    873                                 _type = _definition.typeForIdentifier 
    874                                 _receiverType = _definition.typeForReceiver 
     886                                if _definition inherits AbstractMethod or _definition inherits MemberOverload 
     887                                        _transformTo(DotExpr(.token, 'DOT', ThisLit(.token, isVisible=false), MemberExpr(.token), isVisible=false).bindAll) 
     888                                else 
     889                                        _type = _definition.typeForIdentifier 
     890                                        _receiverType = _definition.typeForReceiver 
    875891                        else 
    876892                                if .binarySuperNode inherits AssignExpr and this is .binarySuperNode.left 
     
    14491465                                # _foo(x) --> ._foo(x) 
    14501466                                newCall = CallExpr(.token, .name, .args, true) 
    1451                                 dotted = DotExpr(.token, 'DOT', ThisLit(.token), newCall, true).bindImp 
     1467                                dotted = DotExpr(.token, 'DOT', ThisLit(.token, isVisible=false), newCall, true, isVisible=false).bindImp 
    14521468                                _type = dotted.type to IType 
    14531469                                _transformTo(dotted) 
  • cobra/trunk/Source/Members.cobra

    r1713 r1729  
    828828                                                                expr = IdentifierExpr(token, decl) to Expr 
    829829                                                        else 
    830                                                                 expr = BinaryOpExpr.make(token, 'DOT', ThisLit(token), MemberExpr(token, decl.name)) to Expr 
     830                                                                expr = DotExpr(token, 'DOT', ThisLit(token, isVisible=false), MemberExpr(token, decl.name), isVisible=false) to Expr 
    831831                                                        stmts.add(AssertStmt(token, IsNotNilExpr(token, expr), nil)) 
    832832                                if stmts.count 
  • cobra/trunk/Tests/120-classes/400-methods.cobra

    r1181 r1729  
    1717                p1.setXY(1, 2) 
    1818                p2.setXY(1, 2) 
     19                p1.moreTests 
     20 
     21        def moreTests 
     22                .testInvocations 
     23                .testUnderInvocations 
    1924 
    2025        def setXY(x as int, y as int) 
    2126                _x = x 
    2227                _y = y 
     28 
     29        def x as int 
     30                # poor example as this would normally be a property 
     31                # but we're testing methods in this file, not properties 
     32                return _x 
     33 
     34        def y as int 
     35                return _y 
    2336 
    2437        def someInt as int 
     
    4255        def someObject3 as Point 
    4356                return Point() 
     57 
     58        def testInvocations 
     59                assert .someInt == 5 
     60                assert .someBool 
     61                assert .someString1 == 'aoeu' 
     62                assert .someString2 == '' 
     63                assert .someObject1 == 'aoeu' 
     64                assert .someObject2 == 5 
     65                assert .someObject3.x == 0 and .someObject3.y == 0 
     66 
     67        def _someInt as int 
     68                return 5 
     69                 
     70        def _someBool as bool 
     71                return true 
     72                 
     73        def _someString1 as String 
     74                return 'aoeu' 
     75         
     76        def _someString2 as String 
     77                return '' 
     78 
     79        def _someObject1 as Object 
     80                return 'aoeu' 
     81         
     82        def _someObject2 as Object 
     83                return 5 
     84                 
     85        def _someObject3 as Point 
     86                return Point() 
     87 
     88        def testUnderInvocations 
     89                assert _someInt == 5 
     90                assert _someBool 
     91                assert _someString1 == 'aoeu' 
     92                assert _someString2 == '' 
     93                assert _someObject1 == 'aoeu' 
     94                assert _someObject2 == 5 
     95                assert _someObject3.x == 0 and .someObject3.y == 0