@@ -40,11 +40,13 @@ MethodDeclaration parseMethodDeclaration(
4040 ParsedSymbol symbol,
4141 ParsedSymbolgraph symbolgraph, {
4242 bool isStatic = false ,
43+ bool isOperator = false ,
4344}) {
4445 final info = parseFunctionInfo (
4546 context,
4647 symbol.json['declarationFragments' ],
4748 symbolgraph,
49+ isOperator: isOperator,
4850 );
4951 return MethodDeclaration (
5052 id: parseSymbolId (symbol.json),
@@ -58,6 +60,7 @@ MethodDeclaration parseMethodDeclaration(
5860 throws: info.throws,
5961 async : info.async ,
6062 mutating: info.mutating,
63+ isOperator: isOperator,
6164 );
6265}
6366
@@ -73,6 +76,7 @@ ParsedFunctionInfo parseFunctionInfo(
7376 Json declarationFragments,
7477 ParsedSymbolgraph symbolgraph, {
7578 bool isEnumCase = false ,
79+ bool isOperator = false ,
7680}) {
7781 // `declarationFragments` describes each part of the function declaration,
7882 // things like the `func` keyword, brackets, spaces, etc.
@@ -111,6 +115,15 @@ ParsedFunctionInfo parseFunctionInfo(
111115 final keyword = maybeConsume ('keyword' );
112116 if (keyword != null ) {
113117 if (keyword == 'func' || keyword == 'init' || keyword == 'case' ) {
118+ if (keyword == 'func' && isOperator) {
119+ final ws1 = maybeConsume ('text' );
120+ final op = maybeConsume ('identifier' );
121+ final ws2 = maybeConsume ('text' );
122+
123+ if (ws1 == null || op == null || ws2 == null ) {
124+ throw malformedInitializerException;
125+ }
126+ }
114127 break ;
115128 } else {
116129 prefixAnnotations.add (keyword);
@@ -146,6 +159,14 @@ ParsedFunctionInfo parseFunctionInfo(
146159 if (sep != ':' ) {
147160 throw malformedInitializerException;
148161 }
162+ } else if (isOperator) {
163+ internalParam = maybeConsume ('internalParam' );
164+ if (internalParam == null ) {
165+ throw malformedInitializerException;
166+ }
167+ if (maybeConsume ('text' ) != ':' ) {
168+ throw malformedInitializerException;
169+ }
149170 } else if (! isEnumCase) {
150171 // Enum cases are allowed to omit both param names. Other param lists
151172 // must at least specify the external name.
@@ -156,8 +177,8 @@ ParsedFunctionInfo parseFunctionInfo(
156177
157178 parameters.add (
158179 Parameter (
159- name: externalParam ?? '' ,
160- internalName: internalParam,
180+ name: isOperator ? (internalParam ?? '' ) : ( externalParam ?? '' ) ,
181+ internalName: isOperator ? null : internalParam,
161182 type: type,
162183 ),
163184 );
0 commit comments