Skip to content

Stack overflows on a structural type definition #12151

Open
@marcin-chwedczuk

Description

@marcin-chwedczuk

reproduction steps

% scala --version
Scala code runner version 2.13.3 -- Copyright 2002-2020, LAMP/EPFL and Lightbend, Inc.

macOS, scala installed via brew install scala.

scala>   type MonadLike[A] = {
     |     def map[B](f: A => B): MonadLike[B]
     |   }
java.lang.StackOverflowError
        at scala.reflect.internal.Types$TypeRef.mapOver(Types.scala:2361)
        at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:728)
        at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:666)
        at scala.reflect.internal.Types$TypeRef.mapOver(Types.scala:2370)
        at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:728)
        at scala.reflect.internal.tpe.TypeMaps$TypeMap.applyToSymbolInfo(TypeMaps.scala:123)
        at scala.reflect.internal.tpe.TypeMaps$TypeMap.loop$1(TypeMaps.scala:117)
        at scala.reflect.internal.tpe.TypeMaps$TypeMap.firstChangedSymbol(TypeMaps.scala:121)
        at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:135)
        at scala.reflect.internal.Types$MethodType.mapOver(Types.scala:2925)
        at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:728)
        at scala.reflect.internal.Types$PolyType.mapOver(Types.scala:3029)

problem

A proper error should be displayed instead of SOE.

Activity

som-snytt

som-snytt commented on Sep 12, 2020

@som-snytt
class C {
  type M[A] = scala.AnyRef {
    def m[B](f: _root_.scala.Function1[A, B]): M[B]
  }
}

And the doti says:

-- [E117] Syntax Error: t12151.scala:4:8 ---------------------------------------
4 |    def m[B](f: _root_.scala.Function1[A, B]): M[B]
  |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |Polymorphic refinement method m without matching type in parent type AnyRef is no longer allowed

Explanation
===========
Polymorphic method m is not allowed in the structural refinement of type AnyRef because
method m does not override any method in type AnyRef. Structural refinement does not allow for
polymorphic methods.

-- [E140] Cyclic Error: t12151.scala:3:7 ---------------------------------------
3 |  type M[A] = scala.AnyRef {
  |       ^
  |illegal cyclic type reference: alias ... of type M refers back to the type itself
2 errors found
changed the title [-]Scala console stack overflows when a structured typed definition is entered[/-] [+]Stack overflows on a structural type definition[/+] on Sep 12, 2020
Jasper-M

Jasper-M commented on Sep 14, 2020

@Jasper-M

This seems to be a regression in 2.13.1.

2.13.0 still emits the illegal cyclic reference error:

scala> type MonadLike[A] = {
     |   def map[B](f: A => B): MonadLike[B]
     | }
         def map[B](f: A => B): MonadLike[B]
                                ^
On line 2: error: illegal cyclic reference involving method map
added this to the Backlog milestone on Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @SethTisue@som-snytt@Jasper-M@marcin-chwedczuk

        Issue actions

          Stack overflows on a structural type definition · Issue #12151 · scala/bug