Skip to content

Error in type parsing and lambda parameter type inference inside tuples #17775

@timotheeandres

Description

@timotheeandres

Compiler version

Scala compiler version 3.0.2

Minimized code

val good1: String => String = _.toLowerCase

val good2 = (s:String) => s.toLowerCase

val (_, good3) = (1, (s: String) => s.toLowerCase)

val (_, good4: String) = (1, "abc")

val (_, bad1: String => String) = (1, _.toLowerCase)

val (_, bad2: (String) => String) = (1, _.toLowerCase)

val (_, bad3: (String => String)) = (1, _.toLowerCase)

val (_, bad4: (String => String)) = (1, s => s.toLowerCase)

Output

-- [E040] Syntax Error: test.scala:9:21 --------------------------------------------------------------------------------
9 |val (_, bad1: String => String) = (1, _.toLowerCase)
  |                     ^^
  |                     ')' expected, but '=>' found
-- [E040] Syntax Error: test.scala:11:23 -------------------------------------------------------------------------------
11 |val (_, bad2: (String) => String) = (1, _.toLowerCase)
   |                       ^^
   |                       ')' expected, but '=>' found
-- [E081] Type Error: test.scala:9:38 ----------------------------------------------------------------------------------
9 |val (_, bad1: String => String) = (1, _.toLowerCase)
  |                                      ^
  |                                      Missing parameter type
  |
  |                                      I could not infer the type of the parameter _$2 of expanded function:
  |                                      _$2 => _$2.toLowerCase.
-- [E081] Type Error: test.scala:11:40 ---------------------------------------------------------------------------------
11 |val (_, bad2: (String) => String) = (1, _.toLowerCase)
   |                                        ^
   |                                        Missing parameter type
   |
   |                                        I could not infer the type of the parameter _$3 of expanded function:
   |                                        _$3 => _$3.toLowerCase.
-- [E081] Type Error: test.scala:13:40 ---------------------------------------------------------------------------------
13 |val (_, bad3: (String => String)) = (1, _.toLowerCase)
   |                                        ^
   |                                        Missing parameter type
   |
   |                                        I could not infer the type of the parameter _$4 of expanded function:
   |                                        _$4 => _$4.toLowerCase.
-- [E081] Type Error: test.scala:15:40 ---------------------------------------------------------------------------------
15 |val (_, bad4: (String => String)) = (1, s => s.toLowerCase)
   |                                        ^
   |                                        Missing parameter type
   |
   |                                        I could not infer the type of the parameter s.
6 errors found

Expectation

I expected the code to compile properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions