Search code examples
runtime-errorrascal

Unexplained "CallFailed" exception when calling constructor function


i have the following method to normalize Java M3 nodes:

public node normalizeNodeDec(ast) {
return top-down visit (ast) {
    case \method(x, _, y, z, q) => \method(Type::short(), "methodName", y, z, q)
    case \method(x, _, y, z) => \method(Type::short(), "methodName", y, z)
    case \parameter(x, _, z) => \parameter(x, "paramName", z)
    case \vararg(x, _) => \vararg(x, "varArgName") 
    case \annotationTypeMember(x, _) => \annotationTypeMember(x, "annonName")
    case \annotationTypeMember(x, _, y) => \annotationTypeMember(x, "annonName", y)
    case \typeParameter(_, x) => \typeParameter("typeParaName", x)
    case \constructor(_, x, y, z) => \constructor("constructorName", x, y, z)
    case \interface(_, x, y, z) => \interface("interfaceName", x, y, z)
    case \class(_, x, y, z) => \class("className", x, y, z)
    case \enumConstant(_, y) => \enumConstant("enumName", y) 
    case \enumConstant(_, y, z) => \enumConstant("enumName", y, z)
    case \methodCall(x, _, z) => \methodCall(x, "methodCall", z)
    case \methodCall(x, y, _, z) => \methodCall(x, y, "methodCall", z) 
    case Type _ => lang::java::jdt::m3::AST::short()
    case Modifier _ => lang::java::jdt::m3::AST::\private()
    case \simpleName(_) => \simpleName("simpleName")
    case \number(_) => \number("1337")
    case \variable(x,y) => \variable("variableName",y) 
    case \variable(x,y,z) => \variable("variableName",y,z) 
    case \booleanLiteral(_) => \booleanLiteral(true)
    case \stringLiteral(_) => \stringLiteral("StringLiteralThingy")
    case \characterLiteral(_) => \characterLiteral("q")
}

But when i run this code i get the following error: Rascal error

Does anyone know what this means and how i can solve this error? I do know that the error points exactly to the line case \method(x, _, y, z, q) => \method(short(), "methodName", y, z, q) and that it highligts q.

I am on rascal stable.

UPDATE: I changed the code accordingly but this still does not seems to solve the error see below: updated code:

public node normalizeNodeDec(ast) {
return top-down visit (ast) {
    case \method(x, _, y, z, q) => \method(Type::short(), "methodName", y, z, q)
    case \method(x, _, y, z) => \method(Type::short(), "methodName", y, z)
    case \parameter(x, _, z) => \parameter(x, "paramName", z)
    case \vararg(x, _) => \vararg(x, "varArgName") 
    case \annotationTypeMember(x, _) => \annotationTypeMember(x, "annonName")
    case \annotationTypeMember(x, _, y) => \annotationTypeMember(x, "annonName", y)
    case \typeParameter(_, x) => \typeParameter("typeParaName", x)
    case \constructor(_, x, y, z) => \constructor("constructorName", x, y, z)
    case \interface(_, x, y, z) => \interface("interfaceName", x, y, z)
    case \class(_, x, y, z) => \class("className", x, y, z)
    case \enumConstant(_, y) => \enumConstant("enumName", y) 
    case \enumConstant(_, y, z) => \enumConstant("enumName", y, z)
    case \methodCall(x, _, z) => \methodCall(x, "methodCall", z)
    case \methodCall(x, y, _, z) => \methodCall(x, y, "methodCall", z) 
    case Type _ => Type::short()
    case Modifier _ => Modifier::\private()
    case \simpleName(_) => \simpleName("simpleName")
    case \number(_) => \number("1337")
    case \variable(x,y) => \variable("variableName",y) 
    case \variable(x,y,z) => \variable("variableName",y,z) 
    case \booleanLiteral(_) => \booleanLiteral(true)
    case \stringLiteral(_) => \stringLiteral("StringLiteralThingy")
    case \characterLiteral(_) => \characterLiteral("q")
}

Updated error: enter image description here


Solution

  • CallFailed happens when the actual parameter types do not line up with formal parameter types of a function. In this case it's a constructor function which fails to apply because of this.

    Unfortunately there is no type-checker in the current stable release to help us realize that there are two version of short() in the current scope, of which silently the "first" one is chosen! There is one from Type and one from TypeSymbol. If it picks the wrong one, you have a match failed because Type and TypeSymbol are incompatible.

    To fix, please use: Type::short() for short() and everything should be fine again.

    That goes for all instances of types in your code so:

    case Type _ => lang::java::jdt::m3::AST::short() should be case Type _ => Type::short() and case Modifier _ => lang::java::jdt::m3::AST::\private() should be case Modifier _ => Modifier::\private()