Packages: [C++] friend function and stray bracket error

Created on 19 May 2016  路  12Comments  路  Source: sublimehq/Packages

I'm seeing an error where having a friend function inside of a class, causes the bracket at the end of that class to be a stray bracket.

stray_bracket

I selected the bracket and ran the following in the console:

>>> view.scope_name(view.sel()[0].b)
'source.c++ meta.class.c++ meta.block.c++ invalid.illegal.stray-bracket-end.c++ '

Here is the same without the friend modifier:

no_stray_bracket

>>> view.scope_name(view.sel()[0].b)
'source.c++ meta.class.c++ meta.block.c++ punctuation.definition.block.end.c++ '
bug

Most helpful comment

class Example {
public:
  friend void example();
  friend bool operator==(const Example &e1, const Example& e2);
};

All 12 comments

I can certainly get this fixed, however I need a little better understanding so that I can make the fix properly.

My understanding was that the friend modifier was followed by a function or class declaration. This would allow the function or class to access private members.

In the example you provided, friend is followed by a function with a body. Currently when friend is defined, we don't scope the function or class name in such a way that it appears in the symbol list or index. However, in your example I would think that it should be present in both lists. Is the example with the function body some different sort of construct?

The second example you provided is just a method that accepts another instance of the class ReallyCool, correct?

The first example shows the same kind of construct as one with no function body, so the answer to your first question is, no - it's the same construct.

For the second question, I simply removed the friend modifier. That code wouldn't actually compile. It should have been something like this:

no_stray_bracket_no_code_bug

I wanted to show that it was the keyword friend that was causing this issue, and I guess I kind of overlooked the fact that the code in the body didn't make sense without that keyword (my bad).

Thanks for looking into this!

On another note, I actually noticed a side effect of this issue, however, I'm guessing the fix will propagate to this as well, but just in case, the side effect is that the keyword namespace seems to be overlooked after the invalid scope. Here's a screenshot:

stray_bracket_and_side_effect

The interesting thing, is that the namespace identifier, TooCool is recognized as a method when the bracket is on a new line, but not when the bracket is on the same line:

# namespace identifier (TooCool)
source.c++ meta.class.c++ meta.block.c++ meta.class.c++ meta.block.c++ meta.class.c++ meta.block.c++ meta.method.c++

stray_bracket_and_side_effect_2

# namespace identifier (TooCool)
source.c++ meta.class.c++ meta.block.c++ meta.class.c++ meta.block.c++ meta.class.c++ meta.block.c++

Just for reference, namespaces should look like this for my color scheme:

namespace

# namespace keyword
source.c++ meta.namespace.c++
# namespace identifier (TooCool)
source.c++ meta.namespace.c++ entity.name.namespace.c++

This should be fixed by 4bbd538e869025244857ced1aba1ae12baa905b2

@wbond I have this problem too, it's not fix yet.

Can you provide an example where friend is not highlighted?

class Example {
public:
  friend void example();
  friend bool operator==(const Example &e1, const Example& e2);
};

Sorry, I forgot the description:

The scope of example should be

source.c++ meta.class.c++ meta.block.c++ meta.method.c++ entity.name.function.c++

but it is actually

source.c++ meta.class.c++ meta.block.c++

and the scope of operator== has the same problem too.

Thanks!

There seem to be some strange decisions regarding friend in the syntax tests:

    friend int func(int a, int b);
/*  ^ storage.modifier */
/*         ^ storage.type */
/*             ^ - entity.name.function */
/*             ^ - meta.function-call */

this is inside a class, so func should definitely be an entity.name.function.

@rwols, I just realized my issue is different with this one, should I open another issue for this ?

Yeah, please do that 馃憤

1082

Was this page helpful?
0 / 5 - 0 ratings