Skip to content

Unexpected literal widening without a Singleton upperbound (post-SIP23) #10838

Open
@soronpo

Description

@soronpo

Consider the following behavior, post SIP23 implementation.

def fooInt[T <: Int](t : T) : T = t  
def fooXInt[T <: Int with Singleton](t : T) : T = t
val one = 1
fooInt(1) //Int = 1
fooInt(one) //Int = 1
fooXInt(1) //Int(1) = 1
fooXInt(one) //fails

The above forces the user to express two different functions, if the narrow literal type information needs to be preserved, in case a literal is used.

Can this be considered a bug? To resolve this we need to either change the widening semantics or add some kind of language construct that forces the narrowed type.


also discussed briefly at: https://gitter.im/typelevel/scala?at=5ad895596bbe1d273902766d

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions