Back to Scala3

E008: Not A Member

docs/_docs/reference/error-codes/E008.md

3.8.41.3 KB
Original Source

E008: Not A Member

This error is emitted when trying to access a member (method, field, or type) that does not exist on the given type. This commonly occurs when:

  • Misspelling a method or field name
  • Using a method that doesn't exist on the type
  • Forgetting to import an extension method

Example

scala
val result = "hello".unknownMethod

Error

scala
-- [E008] Not Found Error: example.scala:1:21 ----------------------------------
1 |val result = "hello".unknownMethod
  |             ^^^^^^^^^^^^^^^^^^^^^
  |             value unknownMethod is not a member of String

Solution

scala
// Use a method that exists on the type
val result = "hello".toUpperCase
scala
// Check the spelling and use the correct method name
val result = "hello".length
scala
// Import extension methods if needed
extension (s: String)
  def unknownMethod: String = s.reverse

val result = "hello".unknownMethod
<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. --> <aside class="warning"> This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios. </aside>