Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflows on a structural type definition #12151

Open
marcin-chwedczuk opened this issue Sep 12, 2020 · 2 comments
Open

Stack overflows on a structural type definition #12151

marcin-chwedczuk opened this issue Sep 12, 2020 · 2 comments

Comments

@marcin-chwedczuk
Copy link

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.

@som-snytt
Copy link

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

@som-snytt som-snytt changed the title Scala console stack overflows when a structured typed definition is entered Stack overflows on a structural type definition Sep 12, 2020
@Jasper-M
Copy link

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

@SethTisue SethTisue added this to the Backlog milestone Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants