diff --git a/README.md b/README.md index 461f76f..02915fc 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,8 @@ If a function repeats a parameter name, `claro typecheck` reports the declaratio Function greet declares parameter name more than once. Give each parameter a different name. ``` +The same declaration check applies to object methods in both syntax styles. For example, `TEACH greet name, name` inside `CLASS Player` reports `Method Player.greet declares parameter name more than once. Give each parameter a different name.` + Simple functions and object methods can also declare a return type. `claro typecheck` checks each `RETURN` expression against it and reports a missing return when a declaration never returns a value: ```claro diff --git a/docs/ADVANCED_STATIC_TYPING.md b/docs/ADVANCED_STATIC_TYPING.md index 153ac4a..2b47710 100644 --- a/docs/ADVANCED_STATIC_TYPING.md +++ b/docs/ADVANCED_STATIC_TYPING.md @@ -608,6 +608,22 @@ The focused validation matrix covers modern and compatibility syntax, including ## Object method parameter checks +Method declarations also reject repeated parameter names before calls are checked. This protects both the modern `TEACH ... END` form and the compatibility `TAKES` / `LEARNED` form: + +```claro +CLASS Player + TEACH greet name, name + SAY name + END +END +``` + +```text +Method Player.greet declares parameter name more than once. Give each parameter a different name. +``` + +Give every method parameter a different name. The focused validation matrix covers both method spellings. + Claro also checks simple object method arguments when the method body names a parameter with `CHECK TYPE`. This keeps the method syntax beginner-readable while giving a clearer error before the program runs: ```claro diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 02f5cbc..5dffb06 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -55,7 +55,7 @@ Ready now: - typed list/map checks through `claro typecheck`, including a nested `LIST OF MAP` insertion example - simple function and object-method return checks with `TEACH name ... RETURNS TYPE`, including learner-facing diagnostics for unknown declared return types, mismatched or not-yet-inferable `RETURN` expressions (including method-specific diagnostics naming the class and method, with modern and compatibility method coverage), empty `RETURN` statements, declarations that contain no `RETURN`, and declarations whose only return is inside an incomplete conditional; `RETURNS` is case-insensitive like other Claro keywords and has positive coverage in both modern and compatibility function forms, including lowercase compatibility declarations and lowercase compatibility method declarations, plus a lowercase compatibility-method mismatch diagnostic; `CHECK TYPE` parameter metadata also informs arithmetic return-expression checking, including method return expressions; positive function-return coverage includes numeric multiplication; compatibility methods now have dedicated positive numeric addition, subtraction, division, and multiplication return fixtures plus compatibility addition, subtraction, division, and multiplication diagnostic fixtures; NUMBER return diagnostics name a known TEXT operand and arithmetic operation instead of hiding the cause behind a generic mismatch, with focused addition, subtraction, multiplication, and division coverage for functions and methods; typed methods can also return class-declared fields by simple name, with positive and mismatch coverage in both modern and compatibility method syntax - a narrow function/method argument check: `CHECK TYPE parameter IS TYPE` inside a function or simple object method lets `claro typecheck` accept correct checked calls, catch mismatched `DO`, `CALL ... WITH`, `DO object.method ...`, and compatibility `CALL object.method WITH ...` arguments, including checked methods that appear after another method in the same class, report missing checked function and method arguments, report missing unchecked arguments for simple functions and simple object methods in both modern `DO` and compatibility `CALL ... WITH` forms, treat empty compatibility calls such as `CALL greet WITH` and `CALL player.rename WITH` as missing-argument mistakes, catch extra arguments to simple functions and checked methods even when the checked method appears after another method in the same class, catch modern `DO` and compatibility `CALL ... WITH` calls to undeclared simple functions, explain when `DO object.method ...` or compatibility `CALL object.method ...` happens before the object is created with `NEW` even if the method name is also wrong, and catch modern plus compatibility calls to undeclared object methods with a class-specific `TEACH` hint -- function and method declarations now reject repeated parameter names with a direct repair hint before calls are checked, including compatibility `TAKES` / `LEARNED` functions +- function and method declarations now reject repeated parameter names with a direct repair hint before calls are checked, including modern and compatibility `TAKES` / `LEARNED` functions and methods - a narrow object-field assignment/check-type check for simple `NEW Class object` plus direct `SET object.field value` and `CHECK TYPE object.field IS TYPE` cases when the class declares `HAS field TYPE`; validation now covers correct NUMBER, TEXT, and YESNO direct assignments, explicitly typed field assignments, explicitly typed method-body assignments to undeclared fields with a `HAS field TYPE` repair hint in modern and compatibility method syntax, dedicated positive NUMBER/TEXT/YESNO `CHECK TYPE` metadata fixtures, simple and chained object aliases for both field assignments and `CHECK TYPE` metadata (including a chained TEXT-field check), aliased object-method calls including chained aliases in modern `DO` and compatibility `CALL ... WITH` forms (with a dedicated positive modern `DO` chained-alias fixture), field-to-field, compound arithmetic field expressions, and arithmetic/text expression result types, negative NUMBER/TEXT/YESNO field `CHECK TYPE` metadata mismatches, NUMBER/TEXT/YESNO-expectation unknown-field `CHECK TYPE` diagnostics, missing-object field assignment and `CHECK TYPE` diagnostics, NUMBER/TEXT/YESNO wrong-type diagnostics, field collection when a `HAS` field appears after a simple method, NUMBER/TEXT/YESNO-valued unknown-field diagnostics for direct assignments to undeclared fields including explicitly typed assignments, numeric and text results from simple arithmetic/text expressions in object-field assignments, plus method-body field assignment and `CHECK TYPE` diagnostics for NUMBER, TEXT, and YESNO fields in modern and compatibility syntax, including compatibility YESNO `CHECK TYPE` metadata coverage, direct method assignments to undeclared fields now produce a beginner-facing missing-field diagnostic when the assigned expression has a known type, and a plain beginner-facing unknown-field diagnostic when the assigned expression is not inferable yet in both modern and compatibility method syntax; method-body `CHECK TYPE` now reports an undeclared bare field with the expected type as a repair hint in both modern and compatibility method syntax, including compatibility `TAKES` / ...; explicitly typed assignments to declared method fields now validate the class-declared field type instead of trusting only the inline type annotation, so a wrong value such as `SET score TEXT "oops"` reports the method and field in the diagnostic Still needed: diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 39b5cd0..91813f7 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -52,7 +52,7 @@ Keep declared return types honest: `claro typecheck` now reports friendly diagno 8e. Keep inline method-field annotation coverage aligned across syntax generations: compatibility `TAKES` / `LEARNED` methods now have matching positive and negative fixtures, so older lessons retain the same class-declared-type guidance. 8f. Keep inline method-field annotations learner-facing: an unknown annotation such as `BANANA` now names the field and method and suggests the `HAS` type instead of silently treating the annotation as an expression. 8g. Keep unknown inline method-field annotation diagnostics aligned across syntax generations: compatibility `TAKES` / `LEARNED` methods now have matching focused coverage for misspelled annotations. -8h. Keep function declarations unambiguous: `claro typecheck` now reports repeated parameter names with a repair hint, before duplicate names can make argument diagnostics confusing, including compatibility `TAKES` / `LEARNED` functions. Broader signature validation remains planned. +8h. Keep function and method declarations unambiguous: `claro typecheck` now reports repeated parameter names with a repair hint, before duplicate names can make argument diagnostics confusing, including modern and compatibility `TAKES` / `LEARNED` functions and methods. Broader signature validation remains planned. ### 1. Strong static types diff --git a/tests/typecheck_method_compat_duplicate_param_bad.claro b/tests/typecheck_method_compat_duplicate_param_bad.claro new file mode 100644 index 0000000..0221770 --- /dev/null +++ b/tests/typecheck_method_compat_duplicate_param_bad.claro @@ -0,0 +1,8 @@ +CLASS Player + TEACH greet TAKES name, name + SAY name + LEARNED +ENDCLASS + +NEW Player player +CALL player.greet WITH "Ada", "Grace" diff --git a/tests/typecheck_method_duplicate_param_bad.claro b/tests/typecheck_method_duplicate_param_bad.claro new file mode 100644 index 0000000..3908cfb --- /dev/null +++ b/tests/typecheck_method_duplicate_param_bad.claro @@ -0,0 +1,8 @@ +CLASS Player + TEACH greet name, name + SAY name + END +END + +NEW Player player +DO player.greet "Ada", "Grace" diff --git a/tools/validate_typecheck_diagnostics.py b/tools/validate_typecheck_diagnostics.py index 716318e..c288d01 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -13,6 +13,12 @@ EXPECTED = { "tests/typecheck_function_compat_duplicate_param_bad.claro": [ "tests/typecheck_function_compat_duplicate_param_bad.claro:1: Function greet declares parameter name more than once. Give each parameter a different name.", ], + "tests/typecheck_method_duplicate_param_bad.claro": [ + "tests/typecheck_method_duplicate_param_bad.claro:2: Method Player.greet declares parameter name more than once. Give each parameter a different name.", + ], + "tests/typecheck_method_compat_duplicate_param_bad.claro": [ + "tests/typecheck_method_compat_duplicate_param_bad.claro:2: Method Player.greet declares parameter name more than once. Give each parameter a different name.", + ], "tests/typecheck_bad.claro": [ "tests/typecheck_bad.claro:2: Type mismatch for score: it was first set as NUMBER, but this value looks like TEXT.", "tests/typecheck_bad.claro:3: Type mismatch for name: expected TEXT, but this value looks like NUMBER.",