rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.67k stars 442 forks source link

No warning on unused but initialised parameters in React components #7041

Open remitbri opened 2 weeks ago

remitbri commented 2 weeks ago

When declaring a React component, unused but initialised parameters don't get the warning flag "unused variable xxx"

@react.component
let make = (
  ~unused1,    // unused variable unused1.
  ~unsused2=true, 
  ~unused3=?,    // unused variable unused3.
  ~text=?
) => {
  <div> {React.string(text->Option.getOr(""))} </div>
}

If it's a "regular" function, the same parameter gets the warning

let foo = (
  ~unused1,   // unused variable unused1.
  ~unsused2=true,   // unused variable unsused2.
  ~unused3=?,    // unused variable unused3.
  ~text=?) =>
 text->Option.getOr("")

Using the playground, it seems the bug appeared with v10.1.2 and is still there for v11.x and v12.x

zth commented 1 week ago

I believe this is because the JSX v4 emits a switch for the default param case, although not sure. cc @mununki