Repository navigation
Suggest replacing if-then-else with case-of when working on Maybe values - #73
Conversation
|
I suspect the implementation here is way too naive, given that the provided test cases look very simple and do not contain the issues I would consider potentially problematic and needing special attention during the invention of variable names etc. For example, what would currently happen to code like this: f m = let value = 42 in if isJust m then value else 0or this: f m = let value = 42 in if isJust m then value + fromJust m else 0or this: f m = if isJust m then (m, fromJust m) else (Just 42, 0)or this: f value = if isJust value then fromJust value else 0or this: f m = if isJust m
then let value = 100 in fromJust m + value
else 0etc. (also for stuff not introduced via Also nested occurrences of such patterns, where then the repeated use of always Or cases where not the f m = if isJust m then let m = Just 99 in fromJust m else 0(the Even weirder but possibly not unthinkable: f m = let fromJust _ = 99
in if isJust m then fromJust m else 0Many of these things might be so unrealistic/unexpected in student code that the checker could be conservative and simply not do anything on code that does such shadowing (e.g., of the Maybe it is also reasonable to take a step back first and consider whether there are systematic alternatives to achieve the aim. Can |
|
HLint does actually allow me to transform if-expressions into case-of-expressions, but the problems you mentioned in the last comment still apply. It doesn't do any name resolution, so we can't really check if |
… not clash with others
|
Separate ChatGPT usage resulted in the following claims about the test suite additions: The non-variable-scrutinee test does not test its stated restrictionAt TaskSpec.hs:287–295, the branch contains: fromMaybe (f val)instead of: fromJust (f val)The detector would return no opportunity even if its restriction to variable scrutinees were removed, because there is no matching Changing this to Two positive fixtures contain unbound variablesThe nested-expression fixture at TaskSpec.hs:249–250 says: def mVal1 mVal 2 = ...while its body uses The mixed-shadowing fixture at TaskSpec.hs:326–327 binds The latter still tests some traversal behavior, but it compares an unresolved outer name with a resolved inner binding. It does not test the intended situation of two valid, differently scoped bindings. These mistakes are possible because the helper parses the snippets and invokes feedback directly; it does not typecheck them. Enabled detection is not tested through the grading pipelineThe new Maybe-specific tests call The most useful integration additions would exercise an actual opportunity through
The current phase placement looks consistent with the documentation by inspection, but the tests do not establish those behaviors. The first four test labels are rotatedThe issue is broader than the one label mentioned by the existing automated review:
All four forms are present, so this is misleading labeling rather than missing coverage. The affected tests are at TaskSpec.hs:89–130. |
I only implemented the first three checks here. The rest can be added in another PR The comments from the other repo are also mostly covered by the changes. I'm only delegating the "restrict allowed extensions" portion to another PR |
if-then-else with case-of when working on Maybe values
This comment was marked as resolved.
This comment was marked as resolved.
|
Are there any cases left now (apart from syntax that will anyway not be available to students when the bans on certain extensions go into effect) where we know that something might go wrong (due to shadowing, or unexpected namings, function identification not taking qualified imports into account or similar; like the stuff you mentioned "hlint is also doing/ignoring), but we simply accept that and will not pursue more strict analysis? Then representative cases for that could be added to the test suite, with explicit declaration "We know this is flagged, even though it is a false positive; or We know this will not be found, despite it actually being a positive." In order to not lose that knowledge. Similarly to how for the inlining-checker there are cases in the test suite of "Actually, one could inline here, but we decided to not complicate the implementation to catch this case as well." |



No description provided.