@Incubating
class MonadicShapeChecker
extends TypeCheckingDSL
Compile-time lint for native monadic chains over the standard carrier allow-list (MonadicCarrierRegistry).
Sister to MonadicChecker: that one repairs erasure on calls routed
through the DO macro's runtime dispatcher; this one catches shape
bugs in hand-written flatMap/map (and
thenCompose/thenApply/etc.) chains that the JDK generics
cannot reject:
bind returning a non-carrier — e.g.
Optional.flatMap { it + 1 } where the JDK expects an
Optional. STC can silently let closures pass this gap.bind returning a different carrier — e.g.
Stream.flatMap { Optional.of(it) }. Almost certainly a bug.map returning the same carrier — e.g.
Optional.map { Optional.of(it) } producing
Optional<Optional<T>>; usually a missed flatMap (or
thenCompose).@Reducer). Calls whose target is Comprehensions are
skipped — they are MonadicChecker's domain.
Two modes, selected via the extension option mode:
// default (lenient): only flag high-confidence problems
@TypeChecked(extensions = 'groovy.typecheckers.MonadicShapeChecker')
// strict: also flag chains whose function return cannot be statically resolved
@TypeChecked(extensions = "groovy.typecheckers.MonadicShapeChecker(mode: 'strict')")
| Constructor and description |
|---|
MonadicShapeChecker() |
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.