You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
traitTrait {
typeT<:Tuplevalt:Tdeffoo[A](f: Tuple.Fold[T, A, Function1]):A= {
definner[TI<:Tuple](t: TI, fOrA: Tuple.Fold[TI, A, Function1]):A= {
typeHead=Tuple.Head[TI]
typeTail=Tuple.Tail[TI]
typeF=Head=>Tuple.Fold[Tail, A, Function1]
(t, fOrA) match {
case (EmptyTuple, a: A@unchecked) => a
case ((head: Head@unchecked) *: (tail: Tail@unchecked), f: F@unchecked) => inner(tail, f(head))
case _ =>thrownewMatchError("It should be impossible to get here")
}
}
inner(t, f)
}
}
objectObjectextendsTrait {
typeT= (Int, String)
valt= (1, "foo")
// doesn't compile: infers A to be NothingvallistNoType= foo { i => s =>List.fill(i)(s) }
// compilesvaltypedList:List[String] = foo { i => s =>List.fill(i)(s) }
// compilesvaltypedCall= foo[List[String]] { i => s =>List.fill(i)(s) }
}
Output
-- [E007] TypeMismatchError: .../Test.scala:26:4726|vallistNoType= foo { i => s =>List.fill(i)(s) }
| ^^^^^^^^^^^^^^^
|Found:List[String]
|Required:Nothing|----------------------------------------------------------------------------|Explanation (enabled by `-explain`)
|--------------------------------------||Tree:List.fill[String](i)(s)
|I tried to show that
|List[String]
| conforms to
|Nothing| but none of the attempts shown below succeeded:
||==>List[String] <:Nothing=false||The tests were made under a constraint with:| uninstantiated variables: A| constrained types: [A](f: Tuple.Fold[Object.T, A, [T1, R] =>>T1=>R]):A|bounds:
|A|ordering:
| co-deps:
| contra-deps:
----------------------------------------------------------------------------
one error found
Expectation
I would expect the type of A to be inferred as List[String] without explicit type annotations, as that is what the function returns. Instead, the compiler infers A as Nothing and then expects the function to return Nothing
The text was updated successfully, but these errors were encountered:
Compiler version
3.5.1
Minimized code
Output
Expectation
I would expect the type of
A
to be inferred asList[String]
without explicit type annotations, as that is what the function returns. Instead, the compiler infersA
asNothing
and then expects the function to returnNothing
The text was updated successfully, but these errors were encountered: