E0007

E0007#

Warning name: unused_field

Field is never read. This include fields in structs and fields in enum constructors.

Erroneous example#

///|
priv enum E {
  A(Int)
  B(value~ : Int)
}

///|
priv struct S {
  value : Int
}

///|
test {
  ignore(B(value=1))
  match A(1) {
    A(_) => println("A")
    B(_) => println("B")
  }
  ignore(S::{ value : 1 })
}

Suggestion#

  • If the fields in enum constructors are unused, you can expand them in the pattern to use them:

    
    ///|
    priv enum  {
      ()
      (value~ : )
    }
    
    ///|
    priv struct  {
       : 
    }
    
    ///|
    test {
      ((=1))
      match (1) {
        () => ("A(\{x})", ="A(1)")
        () => ("B(\{value})")
      }
      let  = ::{ : 1 }
      match  {
        {  } => ("S(\{value})")
      }
      ("S(\{s.value})")
    }
    
  • If the fields are indeed useless, you can remove the field from the constructor:

    
    ///|
    priv enum  {
      
      
    }
    
    ///|
    priv struct  {}
    
    ///|
    test {
      (::)
      match :: {
         => ("A")
         => ("B")
      }
      (::{  })
    }
    
  • If the fields are expected to be used by the others, you can mark the type as pub or pub(all).

    
    ///|
    pub enum  {
      ()
      (value~ : )
    }
    
    ///|
    pub struct  {
       : 
    }