diff --git a/README.md b/README.md index 7a92d98..2143cdd 100644 --- a/README.md +++ b/README.md @@ -231,10 +231,10 @@ Type mismatch for field alias.score: expected NUMBER, but this value looks like The same check follows simple arithmetic and text-concatenation expressions. For example, `SET player.score player.name + 1` reports that the value looks like `TEXT`, rather than silently accepting an expression whose result cannot fit the `NUMBER` field. -The checker also identifies text operands in other arithmetic expressions. For example, `SET player.score player.score - player.name` reports the text result instead of silently treating an invalid numeric subtraction as unknown: +The checker also identifies text operands in other arithmetic expressions. For example, `SET player.score player.score - player.name` now explains the operator rule and names the operand, rather than silently treating an invalid numeric subtraction as unknown: ```text -Type mismatch for field player.score: expected NUMBER, but this value looks like TEXT. +Type mismatch for field player.score: subtraction needs NUMBER values, but player.name looks like TEXT. ``` TEXT-valued and YESNO-valued field-name mistakes are validated too: diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 98dbe0d..5d5d7cc 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -57,7 +57,7 @@ Ready now: Still needed: - Keep the focused typecheck validator's fixture list complete as new positive and negative examples are added. -- The expression checker now carries a known TEXT operand through all arithmetic operators so object-field diagnostics do not hide subtraction, multiplication, or division mistakes; focused numeric-division and numeric-multiplication positives plus text-operand subtraction, multiplication, and division negatives protect this behavior, while operator-specific diagnostics remain planned. +- The expression checker now carries a known TEXT operand through all arithmetic operators so object-field diagnostics do not hide subtraction, multiplication, or division mistakes; focused numeric-division and numeric-multiplication positives plus text-operand subtraction, multiplication, and division negatives protect this behavior. Subtraction now also names the text operand and explains that subtraction needs NUMBER values; multiplication/division-specific guidance remains planned. - richer typed function signatures and return values - type checking through branches and loops - richer object field type checking beyond simple direct assignments diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 4a4d500..3a73bd9 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -36,7 +36,7 @@ See `CURRENT_STATUS.md` for the detailed feature matrix. 3b. Keep package security validation in Forgejo/Gitea CI so unsafe names, exact manifest-version/name/version/checksum mismatches, missing manifests, duplicate project manifest versions and packages, duplicate lock packages, duplicate package manifest names, versions, and checksums, and lockfile errors remain release blockers. 4. Add small examples for each foundation feature before adding bigger syntax. The object-field foundation now includes positive and negative validation for field expressions such as `SET player.score player.name`, `SET player.score player.score + 1`, `SET player.name player.score + 1`, explicitly typed field assignments, simple and chained aliases such as `SET alias player`, `SET backup alias`, followed by `SET backup.score ...` or `CHECK TYPE backup.score IS ...`, chained aliases in object-method calls through both modern `DO` and compatibility `CALL ... WITH` forms (including a dedicated positive modern `DO` fixture), and arithmetic/text expression mismatches; typed containers also accept a map with nested type metadata when it is added to a `LIST OF MAP`; broader alias/control-flow checking remains planned. 5. Keep the focused typecheck validator complete: every `typecheck_*.claro` fixture, including positive fixtures, must be exercised by release validation. -6. Continue narrowing expression diagnostics: known TEXT operands now remain visible through non-concatenation arithmetic, with focused numeric-division and numeric-multiplication positives plus text-operand subtraction, multiplication, and division coverage; operator-specific guidance is still future work. +6. Continue narrowing expression diagnostics: known TEXT operands now remain visible through non-concatenation arithmetic, with focused numeric-division and numeric-multiplication positives plus text-operand subtraction, multiplication, and division coverage. Subtraction now gives operator-specific guidance naming the text operand; matching multiplication and division guidance remains future work. ## Complete-platform milestones diff --git a/src/claro.c b/src/claro.c index 2d71105..59a4af0 100644 --- a/src/claro.c +++ b/src/claro.c @@ -555,6 +555,7 @@ static const char *simple_expr_type(Var *types,const char *expr){ if(i>0 && t[i]==0) return type_env_get(types,t); return NULL; } +static const char *text_operand_for_operator(Var *types,const char *expr,char wanted){ static char operand[256]; char tmp[512]; char *t; size_t i; int in_string=0; if(!expr) return NULL; strncpy(tmp,expr,sizeof(tmp)-1); tmp[sizeof(tmp)-1]=0; t=trim_inplace(tmp); for(i=0;t[i];i++){ char *left,*right; const char *lt,*rt; if(t[i]=='"') in_string=!in_string; if(!in_string&&t[i]==wanted){ left=substr(t,t+i); right=xstrdup(t+i+1); lt=simple_expr_type(types,left); rt=simple_expr_type(types,right); if(lt&&ci_eq(lt,"TEXT")){ snprintf(operand,sizeof(operand),"%s",trim_inplace(left)); free(left); free(right); return operand; } if(rt&&ci_eq(rt,"TEXT")){ snprintf(operand,sizeof(operand),"%s",trim_inplace(right)); free(left); free(right); return operand; } free(left); free(right); } } return NULL; } static int type_words_match(const char *need,const char *got){ if(!need||!*need||ci_eq(need,"ANY")) return 1; if(!got||!*got) return 1; if(ci_eq(need,got)) return 1; if((ci_eq(need,"LIST")||ci_eq(need,"MAP")) && starts_ci(got,need)) return 1; if(starts_ci(need,"LIST OF") && ci_eq(got,"LIST")) return 1; if(starts_ci(need,"MAP OF") && ci_eq(got,"MAP")) return 1; if((ci_eq(need,"YESNO")||ci_eq(need,"BOOL")||ci_eq(need,"BOOLEAN")) && (ci_eq(got,"YESNO")||ci_eq(got,"BOOL")||ci_eq(got,"BOOLEAN"))) return 1; if(ci_eq(need,"OBJECT") && (ci_eq(got,"MAP")||starts_ci(got,"OBJECT:"))) return 1; return 0; } static const char *container_member_type(const char *type,const char *kind){ const char *p; static char buf[128]; if(!type||!kind) return NULL; if(!starts_ci(type,kind)) return NULL; p=type+strlen(kind); while(*p&&isspace((unsigned char)*p)) p++; if(!starts_ci(p,"OF")) return NULL; p+=2; while(*p&&isspace((unsigned char)*p)) p++; if(!*p) return NULL; snprintf(buf,sizeof(buf),"%s",p); return trim_inplace(buf); } static void parse_set_for_typecheck2(const char *t,char **name,char **type,char **expr){ const char *rest=t+3; const char *to=find_word_ci(rest,"TO"); const char *as=find_word_ci(rest,"AS"); *name=NULL; *type=NULL; *expr=NULL; if(as&&to&&as