Type @inline constants in the type checker and keep their attributes
Why
The frontend rewrote @inline let x = 1 and @inline(1) let x: int into external x: int = "#rescript-inline", whose only attribute was the @inline payload, and the type checker decoded that again. The rewrite dropped every other attribute, so a deprecated @inline constant warned nowhere and its doc comment was lost. The type checker now reads @inline itself, as it does FFI attributes since #8728, and the reserved primitive name is gone. This is the @inline item of #8624 and proposal 2 of #8733.
modifiedAST expanded tree
/** The old limit. */@deprecated("Use newLimit instead") @inlinelet limit = 10
expanded
modifiedTypedtree inline constant
typed
addedDiagnostic deprecated inline constant
// User.reslet a = Legacy.limit
diagnostic
removedDiagnostic reserved primitive
external answer: int = "#rescript-inline"diagnostic
Review
- Does the generated JavaScript change? No. The typed tree is the same
Tstr_primitivewithKind_inline_const, and everytests/testsoutput is unchanged. - Why does
Ast_checkscallinline_const_of_binding? The general literal check runs before type checking and would add warning 107 to the out-of-range@inlineint error. Calling it first reports only the error, as the frontend rewrite did. - Is an annotated binding such as
@inline let x: int = 3inlined now? No, it stays an ordinary exported value with warning 53. Inlining it would remove its JavaScript export, so that is left for a separate decision.