Ticket #337: no-of-trap.patch
File no-of-trap.patch, 3.7 KB (added by hopscc, 11 years ago) |
---|
-
Source/CobraParser.cobra
2926 2926 else 2927 2927 sugg = '' 2928 2928 .throwError(ErrorMessages.syntaxErrorAfterDot + sugg) 2929 # trap '< TYPE,' and '<TYPE>' as malformed generic specs 2930 if op == 'LT' and left inherits DotExpr and right inherits TypeExpr 2931 sugg = 'If you are calling a generic that syntax should be "<of [right.token.text]..."' 2932 .throwError('Invalid comparison to a Type. [sugg]') 2933 if left inherits CompareExpr 2934 if left.op=='LT' and op == 'GT' and left.left inherits DotExpr and left.right inherits IdentifierExpr 2935 if ((left.left to DotExpr).right inherits MemberExpr) and (left.right to IdentifierExpr).name.isCapitalized 2936 sugg = 'If you are calling a generic that syntax should be "<of [left.right.token.text]..."' 2937 .recordError('Invalid comparison to a Type. [sugg]') 2929 2938 if op.length, left = BinaryOpExpr.make(opToken, op to !, left to !, right) 2930 2939 finally 2931 2940 .opStack.pop -
Tests/820-errors/200-expressions/800-generics/bad-generic-builtin-type.cobra
1 class Program 2 3 def main 4 #.method<int>(14) 5 x= .m1<int>(14) #.error. calling a generic 6 CobraCore.noOp(x) 7 8 def m1<of T> as Type 9 return String 10 -
Tests/820-errors/200-expressions/800-generics/bad-generic-any-type.cobra
1 class Program 2 3 def main 4 #.m1(14) 5 #.method<of int>(i) 6 # x= .m1<int>(14) 7 x = .m1<String>(14) #.error. Invalid comparison to a Type 8 x1 = .m1<Program>(15) #.error. should be "<of Program 9 x2 = .m1<AnyTypeName>(99) #.error. should be "<of AnyTypeName 10 11 x3 = .m2(14)<Program>(20) # this shld not err given above errors 12 13 CobraCore.noOp(x, x1, x2, x3) 14 15 val = 44 16 assert .m3<val>(50) 17 18 def m1<of T> as Type 19 return String 20 21 def m2(a as int) as Type 22 return String 23 24 def m3 as int 25 return 33 26 -
Tests/820-errors/200-expressions/800-generics/bad-generic-call-expr.cobra
1 class Program 2 3 def main 4 x1= .m2(14)<Program>(14) # .error. cannot be compared 5 CobraCore.noOp(x1) 6 7 def m2(a as int) as Type 8 return String -
Tests/820-errors/200-expressions/800-generics/bad-generic-multiple.cobra
1 # .error. general syntax error 2 class Program 3 4 def method<of T>(argument as T) 5 print argument 6 7 def main 8 x= .m1<int,int> (14) #.error. Invalid comparison to a Type 9 #.error general syntax error 10 CobraCore.noOp(x) 11 12 def m1<of T, T1> as Type 13 return String 14