diff --git a/CHANGELOG.md b/CHANGELOG.md index 8491582..6445b5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +### Validate compatibility method return types + +- Added focused coverage proving that the older `TEACH ... TAKES ... RETURNS TYPE` / `LEARNED` method syntax receives the same learner-facing return-type diagnostic as modern methods. +- Added the compatibility method fixture to the complete typecheck diagnostics validator. + ### Validate compatibility function return types - Added focused coverage proving that the older `TEACH ... TAKES ... RETURNS TYPE` / `LEARNED` syntax receives the same learner-facing return-type diagnostic as modern functions. diff --git a/README.md b/README.md index f2cda50..2eadff4 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ END The same focused check applies to methods such as `Player.score RETURNS NUMBER`; a wrong return reports the full method name, for example: `Type mismatch for return from Player.score: expected NUMBER, but this value looks like TEXT.` -The older compatibility spelling keeps the same return check. For example, `TEACH square TAKES amount RETURNS NUMBER` with `LEARNED` and `CALL square WITH 4` is checked before it runs, so older lessons get the same type-safety feedback. +The older compatibility spelling keeps the same return check for functions and methods. For example, `TEACH square TAKES amount RETURNS NUMBER` with `LEARNED` and `CALL square WITH 4` is checked before it runs, so older lessons get the same type-safety feedback. A compatibility method such as `TEACH score TAKES amount RETURNS NUMBER` inside a class is checked the same way. If a function or method declares `RETURNS TYPE` but uses `RETURN` without a value, the checker points out the missing expression: diff --git a/tests/typecheck_method_compat_return_bad.claro b/tests/typecheck_method_compat_return_bad.claro new file mode 100644 index 0000000..68797d7 --- /dev/null +++ b/tests/typecheck_method_compat_return_bad.claro @@ -0,0 +1,9 @@ +CLASS Player + TEACH score TAKES amount RETURNS NUMBER + CHECK TYPE amount IS NUMBER + RETURN "oops" + LEARNED +ENDCLASS + +NEW Player player +CALL player.score WITH 4 diff --git a/tools/validate_typecheck_diagnostics.py b/tools/validate_typecheck_diagnostics.py index e76738d..5fe668d 100644 --- a/tools/validate_typecheck_diagnostics.py +++ b/tools/validate_typecheck_diagnostics.py @@ -37,6 +37,9 @@ EXPECTED = { "tests/typecheck_method_return_bad.claro": [ "tests/typecheck_method_return_bad.claro:3: Type mismatch for return from Player.score: expected NUMBER, but this value looks like TEXT.", ], + "tests/typecheck_method_compat_return_bad.claro": [ + "tests/typecheck_method_compat_return_bad.claro:4: Type mismatch for return from Player.score: expected NUMBER, but this value looks like TEXT.", + ], "tests/typecheck_method_return_expression_bad.claro": [ "tests/typecheck_method_return_expression_bad.claro:4: Type mismatch for return from Player.label: expected TEXT, but this value looks like NUMBER.", ],