This repo illustrates an issue of running reanalyze on a Rescript 11 project and Rescript 12 project. The code is exactly the same, but the output of running reanalyze on each project is different.
We define a React provider which provides a function to dispatch a notification. In this case just printing out a message in the console. We also define a regular function to compare against.
module NotificationProvider = {
let dispatchNotificationContext = React.createContext((
~action as _: option<string>=?,
_message: string,
) => ())
module Provider = {
let make = React.Context.provider(dispatchNotificationContext)
}
@react.component
let make = (~children) => {
let dispatchNotification = (~action=?, message) =>
switch action {
| Some(action) => Console.log2(message, action)
| None => Console.log(message)
}
<Provider value=dispatchNotification> {children} </Provider>
}
let useNotification = () => React.useContext(dispatchNotificationContext)
}
let dispatchNotificationNotFromProvider = (~action: option<string>=?, message) =>
switch action {
| Some(action) => Console.log2(message, action)
| None => Console.log(message)
}
Then we define two components: One using the optional action prop and one that doesn't.
module ComponentUsingAction = {
@react.component
let make = () => {
let dispatchNotification = NotificationProvider.useNotification()
React.useEffect(() => {
dispatchNotification(~action="Some action", "This is a notification message")
dispatchNotificationNotFromProvider(~action="Some action", "This is a notification message")
None
}, [])
React.null
}
}
module ComponentNotUsingAction = {
@react.component
let make = () => {
let dispatchNotification = NotificationProvider.useNotification()
React.useEffect(() => {
dispatchNotification("This is a notification message")
dispatchNotificationNotFromProvider("This is a notification message")
None
}, [])
React.null
}
}
Running yarn rescript-tools reanalyze -dce in the Rescript 12 project yields the output:
Warning Unused Argument
/.../rescript-analyze-issues/rescript-12/src/App.res:49:5-69
optional argument action of function ComponentNotUsingAction.dispatchNotification is never used
Warning Redundant Optional Argument
/.../rescript-analyze-issues/rescript-12/src/App.res:34:5-69
optional argument action of function ComponentUsingAction.dispatchNotification is always supplied (1 calls)
Warning Unused Argument
/.../rescript-analyze-issues/rescript-12/src/App.res:22:3-75
optional argument action of function NotificationProvider.useNotification is never used
Warning Unused Argument
/.../rescript-analyze-issues/rescript-12/src/App.res:13:5-175
optional argument action of function NotificationProvider.dispatchNotification is never used
Analysis reported 4 issues (Warning Redundant Optional Argument:1, Warning Unused Argument:3)
Running the same command (with @rescript/tools 0.6.6 installed) yields the output:
Analysis reported 0 issues
It seems the output from the Rescript 12 project is wrong, as it reports that a optional argument is never used, but when in reality it actually is used by another component.