Skip to content

Commit

Permalink
Fix setting parameter on MagikCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenLooman committed Sep 17, 2023
1 parent 2226216 commit c4c9f25
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public void setParameter(final String name, final @Nullable Object value) throws
continue;
}

final String key = ruleProperty.key().replace(" ", "-");
if (key.equals(name)) {
final String checkKey = this.getHolder().getCheckKeyKebabCase();
final String parameterKey = ruleProperty.key().replace(" ", "-");
final String fullKey = checkKey + "." + parameterKey;
if (fullKey.equals(name)) {
field.set(this, value);
found = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import nl.ramsolutions.sw.magik.analysis.typing.types.TypeString;
import nl.ramsolutions.sw.magik.analysis.typing.types.UndefinedType;
import nl.ramsolutions.sw.magik.api.MagikGrammar;
import nl.ramsolutions.sw.magik.parser.TypeStringParser;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -1520,4 +1521,48 @@ void testGenericIterMethodInvocation() {
.isEqualTo(integerType);
}

@Test
void testGenericSlot() {
final String code = ""
+ "_method exemplar.m\n"
+ " _return .stack.pop()\n"
+ "_endmethod\n";

// Set up TypeKeeper/TypeReasoner.
final TypeKeeper typeKeeper = new TypeKeeper();

final TypeString stackRef = TypeString.ofIdentifier("stack", "sw");
final MagikType stackType = new MagikType(typeKeeper, Sort.SLOTTED, stackRef);
stackType.addGeneric(null, "E");
stackType.addMethod(
null,
EnumSet.noneOf(Method.Modifier.class),
"pop()",
Collections.emptyList(),
null,
null,
new ExpressionResultString(
TypeString.ofGeneric("E")),
new ExpressionResultString());

final TypeString exemplarRef = TypeString.ofIdentifier("exemplar", "sw");
final MagikType exemplarType = new MagikType(typeKeeper, Sort.SLOTTED, exemplarRef);
final TypeString slotTypeRef = TypeStringParser.parseTypeString("sw:stack<sw:integer>", "sw");
exemplarType.addSlot(null, "stack", slotTypeRef);

// Do analysis.
final MagikTypedFile magikFile = this.createMagikFile(code, typeKeeper);
final LocalTypeReasoner reasoner = magikFile.getTypeReasoner();

final AstNode topNode = magikFile.getTopNode();
final AstNode methodDefinitionNode = topNode.getFirstDescendant(MagikGrammar.METHOD_DEFINITION);
final ExpressionResult result = reasoner.getNodeType(methodDefinitionNode);
final TypeString integerRef = TypeString.ofIdentifier("integer", "sw");
final AbstractType integerType = typeKeeper.getType(integerRef);
final AbstractType actualType = result.get(0, null);
assertThat(actualType)
.isNotNull()
.isEqualTo(integerType);
}

}

0 comments on commit c4c9f25

Please sign in to comment.