Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix StarlarkIndexable.getIndex implementations that return null. #15344

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ public Sequence<ConstraintSettingInfo> constraintSettings() {

@Override
public Object getIndex(StarlarkSemantics semantics, Object key) throws EvalException {
return get(convertKey(key));
Object result = get(convertKey(key));
if (result == null) {
result = Starlark.NONE;
}
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.starlark.java.eval.Starlark;
import net.starlark.java.eval.StarlarkSemantics;
import net.starlark.java.eval.StarlarkThread;
import net.starlark.java.eval.StarlarkValue;

/**
* An implementation of ToolchainContextApi that can better handle converting strings into Labels.
Expand Down Expand Up @@ -99,7 +100,7 @@ private Label transformKey(StarlarkThread starlarkThread, Object key) throws Eva
}

@Override
public ToolchainInfo getIndex(
public StarlarkValue getIndex(
StarlarkThread starlarkThread, StarlarkSemantics semantics, Object key) throws EvalException {
Label toolchainTypeLabel = transformKey(starlarkThread, key);

Expand All @@ -116,7 +117,11 @@ public ToolchainInfo getIndex(
.map(Label::toString)
.collect(joining(", ")));
}
return toolchainContext().forToolchainType(toolchainTypeLabel);
ToolchainInfo toolchainInfo = toolchainContext().forToolchainType(toolchainTypeLabel);
if (toolchainInfo == null) {
return Starlark.NONE;
}
return toolchainInfo;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.devtools.build.skyframe.SkyKey;
import javax.annotation.Nullable;
import net.starlark.java.eval.Printer;
import net.starlark.java.eval.Starlark;
import net.starlark.java.eval.StarlarkSemantics;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -253,7 +254,7 @@ public void repr(Printer printer) {}

@Override
public Object getIndex(StarlarkSemantics semantics, Object key) {
return null;
return Starlark.NONE;
}

@Override
Expand Down