package org.metaborg.meta.nabl2.spoofax.primitives;

import org.metaborg.meta.nabl2.stratego.StrategoTermIndex;
import org.spoofax.interpreter.core.IContext;
import org.spoofax.interpreter.core.InterpreterException;
import org.spoofax.interpreter.core.Tools;
import org.spoofax.interpreter.library.AbstractPrimitive;
import org.spoofax.interpreter.stratego.Strategy;
import org.spoofax.interpreter.terms.IStrategoAppl;
import org.spoofax.interpreter.terms.IStrategoTerm;

public class SG_set_ast_index extends AbstractPrimitive {

    public SG_set_ast_index() {
        super(SG_set_ast_index.class.getSimpleName(), 0, 1);
    }

    @Override public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {
        if (Tools.isTermAppl(tvars[0])) {
            throw new InterpreterException("Term argument is not a TermIndex");
        }
        StrategoTermIndex termIndex = StrategoTermIndex.TYPE.fromTerm((IStrategoAppl)tvars[0]);
        env.current().putAttachment(termIndex);
        return true;
    }

}
@@ -755,16 +755,17 @@
     if (
+!
 Tools.is
@@ -972,16 +972,139 @@
 rs%5B0%5D);%0A
+        if (termIndex == null) %7B%0A            throw new InterpreterException(%22Term argument is not a TermIndex%22);%0A        %7D%0A
         

Use correct test.