|
16 | 16 | import javax.lang.model.element.TypeElement;
|
17 | 17 | import javax.lang.model.element.VariableElement;
|
18 | 18 | import javax.lang.model.type.TypeKind;
|
| 19 | +import javax.lang.model.type.TypeMirror; |
| 20 | +import javax.lang.model.util.Elements; |
| 21 | +import javax.lang.model.util.Types; |
19 | 22 | import javax.tools.Diagnostic;
|
20 | 23 |
|
21 | 24 | import com.oracle.truffle.api.dsl.CachedLanguage;
|
@@ -161,7 +164,7 @@ private static void checkAmbiguousOptionalArguments(
|
161 | 164 | specializationMethod);
|
162 | 165 | return;
|
163 | 166 | }
|
164 |
| - isParameterUnguarded(coreModuleProcessor, specializationAnnotation, parameters.get(n)); |
| 167 | + isParameterBlock(coreModuleProcessor, parameters.get(n)); |
165 | 168 | n--; // Ignore block argument.
|
166 | 169 | }
|
167 | 170 |
|
@@ -239,4 +242,24 @@ private static boolean isGuarded(String name, String[] guards) {
|
239 | 242 | }
|
240 | 243 | return false;
|
241 | 244 | }
|
| 245 | + |
| 246 | + private static void isParameterBlock( |
| 247 | + CoreModuleProcessor coreModuleProcessor, |
| 248 | + VariableElement parameter) { |
| 249 | + TypeMirror blockType = parameter.asType(); |
| 250 | + Types typeUtils = coreModuleProcessor.getProcessingEnvironment().getTypeUtils(); |
| 251 | + Elements elementUtils = coreModuleProcessor.getProcessingEnvironment().getElementUtils(); |
| 252 | + boolean isNil = typeUtils |
| 253 | + .isSameType(blockType, elementUtils.getTypeElement("org.truffleruby.language.Nil").asType()); |
| 254 | + boolean isRubyProc = typeUtils |
| 255 | + .isSameType(blockType, elementUtils.getTypeElement("org.truffleruby.core.proc.RubyProc").asType()); |
| 256 | + boolean isObject = typeUtils.isSameType(blockType, coreModuleProcessor.objectType); |
| 257 | + |
| 258 | + if (!(isNil || isRubyProc || isObject)) { |
| 259 | + coreModuleProcessor.getProcessingEnvironment().getMessager().printMessage( |
| 260 | + Diagnostic.Kind.ERROR, |
| 261 | + "A block parameter must be of type Nil, RubyProc or Object.", |
| 262 | + parameter); |
| 263 | + } |
| 264 | + } |
242 | 265 | }
|
0 commit comments