File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
src/com/goide/highlighting Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,34 @@ else if (element instanceof GoBuiltinCallExpr) {
112112 checkMakeCall (call , holder );
113113 }
114114 }
115+ else if (element instanceof GoCallExpr ) {
116+ GoCallExpr call = (GoCallExpr )element ;
117+ if (call .getExpression () instanceof GoReferenceExpression ) {
118+ GoReferenceExpression reference = (GoReferenceExpression )call .getExpression ();
119+ if ("cap" .equals (reference .getText ())) {
120+ if (GoPsiImplUtil .builtin (reference .getReference ().resolve ())) {
121+ checkCapCall (call , holder );
122+ }
123+ }
124+ }
125+ }
126+ }
127+
128+ private static void checkCapCall (@ NotNull GoCallExpr capCall , @ NotNull AnnotationHolder holder ) {
129+ if (capCall .getArgumentList ().getExpressionList ().size () != 1 ) {
130+ return ;
131+ }
132+ GoType exprType = capCall .getArgumentList ().getExpressionList ().get (0 ).getGoType (null );
133+ if (exprType == null ) {
134+ return ;
135+ }
136+ GoType baseType = getBaseType (exprType );
137+ if (baseType instanceof GoPointerType ) {
138+ baseType = ((GoPointerType )baseType ).getType ();
139+ }
140+ if (!(baseType instanceof GoArrayOrSliceType || baseType instanceof GoChannelType )) {
141+ holder .createErrorAnnotation (capCall .getArgumentList ().getExpressionList ().get (0 ), "Invalid argument for cap" );
142+ }
115143 }
116144
117145 private static void checkMakeCall (@ NotNull GoBuiltinCallExpr call , @ NotNull AnnotationHolder holder ) {
Original file line number Diff line number Diff line change @@ -53,4 +53,21 @@ func main() {
5353 foo (make (chan func (), < error descr = "Non - integer size argument to make "> true < / error > ))
5454 foo (make (chan func (), < error descr = "Non - integer size argument to make "> complex (17 ,4 )< / error > ))
5555 foo (make (chan func (), < error descr = "Non - integer size argument to make "> "1 "< / error > ))
56+
57+ type someChan chan int
58+ type capChan someChan
59+
60+ var capTest1 e
61+ var capTest2 a
62+ var capTest3 capChan
63+ var capTest4 int
64+ foo (cap < error descr = "not enough arguments in call to cap "> ()< / error > )
65+ foo (cap < error descr = "too many arguments in call to cap "> (capTest1 , capTest2 )< / error > )
66+ foo (cap (capTest1 ))
67+ foo (cap (< error descr = "Invalid argument for cap "> capTest2 < / error > ))
68+ foo (cap (capTest3 ))
69+ foo (cap (< error descr = "Invalid argument for cap "> capTest4 < / error > ))
70+ foo (cap (< error descr = "Invalid argument for cap "> map [string ]struct {}{}< / error > ))
71+ foo (cap (& [4 ]string {"a ", "b ", "c ", "d "}))
72+ foo (cap ([]string {}))
5673}
You can’t perform that action at this time.
0 commit comments