Can no longer use functions as dictionary keys

This commit is contained in:
2022-09-11 13:36:59 +01:00
parent 2d171dd664
commit 0f6be5ead7
2 changed files with 23 additions and 4 deletions

View File

@@ -380,7 +380,8 @@ int hashLiteral(Literal lit) {
}
case LITERAL_FUNCTION:
return 0;
case LITERAL_FUNCTION_NATIVE:
return 0; //TODO: find a way to hash these properly
case LITERAL_IDENTIFIER:
return HASH_I(lit); //pre-computed

View File

@@ -136,7 +136,13 @@ void freeLiteralDictionary(LiteralDictionary* dictionary) {
void setLiteralDictionary(LiteralDictionary* dictionary, Literal key, Literal value) {
if (IS_NULL(key)) {
fprintf(stderr, ERROR "[internal] Dictionaries can't have null keys (get)\n" RESET);
fprintf(stderr, ERROR "Dictionaries can't have null keys (get)\n" RESET);
return;
}
//BUGFIX: Can't hash a function
if (IS_FUNCTION(key) || IS_FUNCTION_NATIVE(key)) {
fprintf(stderr, ERROR "Dictionaries can't have function keys (get)\n" RESET);
return;
}
@@ -150,7 +156,13 @@ void setLiteralDictionary(LiteralDictionary* dictionary, Literal key, Literal va
Literal getLiteralDictionary(LiteralDictionary* dictionary, Literal key) {
if (IS_NULL(key)) {
fprintf(stderr, ERROR "[internal] Dictionaries can't have null keys (set)\n" RESET);
fprintf(stderr, ERROR "Dictionaries can't have null keys (set)\n" RESET);
return TO_NULL_LITERAL;
}
//BUGFIX: Can't hash a function
if (IS_FUNCTION(key) || IS_FUNCTION_NATIVE(key)) {
fprintf(stderr, ERROR "Dictionaries can't have function keys (set)\n" RESET);
return TO_NULL_LITERAL;
}
@@ -166,7 +178,13 @@ Literal getLiteralDictionary(LiteralDictionary* dictionary, Literal key) {
void removeLiteralDictionary(LiteralDictionary* dictionary, Literal key) {
if (IS_NULL(key)) {
fprintf(stderr, ERROR "[internal] Dictionaries can't have null keys (remove)\n" RESET);
fprintf(stderr, ERROR "Dictionaries can't have null keys (remove)\n" RESET);
return;
}
//BUGFIX: Can't hash a function
if (IS_FUNCTION(key) || IS_FUNCTION_NATIVE(key)) {
fprintf(stderr, ERROR "Dictionaries can't have function keys (remove)\n" RESET);
return;
}