3737import com .sun .tools .javac .code .Type ;
3838import com .sun .tools .javac .code .Type .ForAll ;
3939import com .sun .tools .javac .code .Type .MethodType ;
40+ import com .sun .tools .javac .code .TypeTag ;
4041import com .sun .tools .javac .code .Types ;
4142import com .sun .tools .javac .comp .Attr ;
4243import com .sun .tools .javac .comp .AttrContext ;
@@ -139,7 +140,14 @@ protected List<Type> expectedTypes(Inliner inliner) throws CouldNotResolveImport
139140 Ordering .natural ()
140141 .immutableSortedCopy (
141142 Iterables .filter (inliner .bindings .keySet (), PlaceholderExpressionKey .class ))) {
142- result .add (key .method .returnType ().inline (inliner ));
143+ Type type = key .method .returnType ().inline (inliner );
144+ // Skip void placeholder expressions, because
145+ // a) if the expected type is void, any actual type is acceptable
146+ // b) these types are used as the argument types in a synthetic MethodType, and method
147+ // argument types cannot be void
148+ if (!type .getTag ().equals (TypeTag .VOID )) {
149+ result .add (type );
150+ }
143151 }
144152 return List .from (result );
145153 }
@@ -149,7 +157,7 @@ protected List<Type> expectedTypes(Inliner inliner) throws CouldNotResolveImport
149157 * bound to the @BeforeTemplate method parameters, concatenated with the types of the expressions
150158 * bound to expression placeholders, sorted by the name of the placeholder method.
151159 */
152- protected List <Type > actualTypes (Inliner inliner ) {
160+ protected List <Type > actualTypes (Inliner inliner ) throws CouldNotResolveImportException {
153161 ArrayList <Type > result = new ArrayList <>();
154162 ImmutableList <String > argNames = expressionArgumentTypes ().keySet ().asList ();
155163 for (int i = 0 ; i < expressionArgumentTypes ().size (); i ++) {
@@ -177,7 +185,11 @@ protected List<Type> actualTypes(Inliner inliner) {
177185 Ordering .natural ()
178186 .immutableSortedCopy (
179187 Iterables .filter (inliner .bindings .keySet (), PlaceholderExpressionKey .class ))) {
180- result .add (inliner .getBinding (key ).type );
188+ Type keyType = key .method .returnType ().inline (inliner );
189+ // See comment in `expectedTypes` for why we skip void placeholder keys.
190+ if (!keyType .getTag ().equals (TypeTag .VOID )) {
191+ result .add (inliner .getBinding (key ).type );
192+ }
181193 }
182194 return List .from (result );
183195 }
0 commit comments