Skip to content

Commit 34ed74d

Browse files
committed
Replace isParameterUnguarded check for block parameters
This allows now-identical `Nil block` and `RubyProc block` specializations to be combined into a single `Object block` specialization. Rather than remove the check entirely, we’re instead checking that the type of the parameter is correct.
1 parent 33d7bd0 commit 34ed74d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/processor/java/org/truffleruby/processor/CoreModuleChecks.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import javax.lang.model.element.TypeElement;
1717
import javax.lang.model.element.VariableElement;
1818
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;
1922
import javax.tools.Diagnostic;
2023

2124
import com.oracle.truffle.api.dsl.CachedLanguage;
@@ -161,7 +164,7 @@ private static void checkAmbiguousOptionalArguments(
161164
specializationMethod);
162165
return;
163166
}
164-
isParameterUnguarded(coreModuleProcessor, specializationAnnotation, parameters.get(n));
167+
isParameterBlock(coreModuleProcessor, parameters.get(n));
165168
n--; // Ignore block argument.
166169
}
167170

@@ -239,4 +242,24 @@ private static boolean isGuarded(String name, String[] guards) {
239242
}
240243
return false;
241244
}
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+
}
242265
}

0 commit comments

Comments
 (0)