Skip to content

Commit

Permalink
[Truffle] Coerce File.exist? argument to String.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Feb 19, 2015
1 parent 0331353 commit 6f5ce08
Showing 1 changed file with 10 additions and 1 deletion.
Expand Up @@ -10,12 +10,16 @@
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.CreateCast;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import jnr.posix.FileStat;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.coerce.ToStrNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.core.*;
Expand Down Expand Up @@ -251,7 +255,8 @@ public boolean executable(RubyString path) {
}

@CoreMethod(names = {"exist?", "exists?"}, onSingleton = true, required = 1)
public abstract static class ExistsNode extends CoreMethodNode {
@NodeChild(value = "path")
public abstract static class ExistsNode extends RubyNode {

public ExistsNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand All @@ -261,6 +266,10 @@ public ExistsNode(ExistsNode prev) {
super(prev);
}

@CreateCast("path") public RubyNode coercePathToString(RubyNode path) {
return ToStrNodeFactory.create(getContext(), getSourceSection(), path);
}

@Specialization
public boolean exists(RubyString path) {
notDesignedForCompilation();
Expand Down

0 comments on commit 6f5ce08

Please sign in to comment.