Get types from type tree in async-related rules#843
Get types from type tree in async-related rules#843knocte merged 7 commits intofsprojects:masterfrom
Conversation
For functions without explicit return types.
Greptile OverviewConfidence Score: 3/5
|
| Filename | Overview |
|---|---|
| src/FSharpLint.Core/Rules/Conventions/Naming/AsynchronousFunctionNames.fs | Refactors naming checks and, when no explicit return type is present, infers Async/Task return type via typed tree lookup (FSharpCheckFileResults). |
| src/FSharpLint.Core/Rules/Conventions/Naming/SimpleAsyncComplementaryHelpers.fs | Switches return-type-param rendering from AST SynType to strings and adds typed-tree inference for missing return annotations; current typed-tree rendering can drop generic arguments and produce incorrect suggested signatures. |
| src/FSharpLint.Core/Rules/Conventions/Naming/SynchronousFunctionNames.fs | Adds typed-tree inference for missing return annotations to detect non-async functions named with Async prefix/suffix; refactors identifier check into helper. |
| src/FSharpLint.Core/Rules/NamingHelper.fs | Updates async prefix/suffix active pattern to ignore double-backticked identifiers; adds FSharpType active pattern to classify Async/Task based on BasicQualifiedName. |
| src/FSharpLint.Core/Rules/Utilities.fs | Introduces TypedTree helper (GetSymbolUseAtLocation + FullType traversal) to infer function return types; current symbol location/ident selection can mis-resolve for qualified/overloaded members. |
| tests/FSharpLint.Core.Tests/Rules/Conventions/AsyncExceptionWithoutReturn.fs | Renames test methods for clarity; no behavioral change. |
| tests/FSharpLint.Core.Tests/Rules/Conventions/Naming/AsynchronousFunctionNames.fs | Adds coverage for typed-tree inference when return type annotation is omitted (Async/Task functions and methods). |
| tests/FSharpLint.Core.Tests/Rules/Conventions/Naming/SimpleAsyncComplementaryHelpers.fs | Adds tests for complementary helper suggestions when return annotations are missing; assumes suggestion includes correct type parameter rendering. |
| tests/FSharpLint.Core.Tests/Rules/Conventions/Naming/SynchronousFunctionNames.fs | Adds tests ensuring non-async functions without explicit return types still trigger naming violations and async ones don’t. |
Sequence Diagram
sequenceDiagram
participant Rule as Naming rule
participant AST as Parsed AST
participant TTC as Utilities.TypedTree
participant Check as FSharpCheckFileResults
participant Sym as FCS Symbol
Rule->>AST: Visit SynBinding
Rule->>AST: Read returnInfo
alt returnInfo present
Rule->>Rule: Classify via ReturnsAsync/ReturnsTask/ReturnsNonAsync
Rule->>Rule: Emit warning if naming mismatches
else returnInfo missing
Rule->>TTC: getFunctionReturnType(checkInfo, lines, funcIdent)
TTC->>Check: GetSymbolUseAtLocation(line,col,lineText,identIsland)
Check-->>TTC: SymbolUse (option)
alt function symbol resolved
TTC->>Sym: Read FullType and compute return type
Sym-->>TTC: FSharpType
TTC-->>Rule: FSharpType (option)
Rule->>Rule: Classify via FSharpTypeAsync/FSharpTypeTask/...
Rule->>Rule: Emit warning if naming mismatches
else not resolved
TTC-->>Rule: None
Rule->>Rule: Skip (no warning)
end
end
Additional Comments (1)
When This also affects any nested generics (e.g., Also appears in the same file where |
c378757 to
c18ce72
Compare
I added a test that uses return type |
This is by design. Function that returns |
If there is no explicit return type.
For functions without explicit return types.
If there is no explicit return type.
For functions without explicit return types.
If there is no explicit return type.
40d54e5 to
240ffd6
Compare
Upon further examination, that test I added was testing the wrong thing. Modified the test. Switched to using |
If output type of function/method is not specified, get it from typed syntax tree.
This affects the following rules:
Contributes to #517.