Skip to content

Omit type parameter in extend clause #4820

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

Closed
allanrenucci opened this issue Jul 20, 2018 · 2 comments
Closed

Omit type parameter in extend clause #4820

allanrenucci opened this issue Jul 20, 2018 · 2 comments

Comments

@allanrenucci
Copy link
Contributor

As opposed to scalac, Dotty lets you write:

trait Foo[A]
class Bar[A] extends Foo

Note that in Dotty and Scala 2, you can write

class Foo[A]
class Bar[A] extends Foo

Here Dotty infers the type parameter toi be Any and scalac infers Nothing.

Does it make sense to infer a type argument when there is no call to the super constructor?

@allanrenucci
Copy link
Contributor Author

Maybe a separate issue: the compiler crashes when compiling

trait SetOps[A, +C <: SetOps[A, C]]  {
  def concat(that: Iterable[A]): C = ???
}

class Set1[A] extends SetOps //should be SetOps[A, Set1[A]]
Exception in thread "main" dotty.tools.dotc.core.TypeError: bad parameter reference Set1.this.C at tryCatchPatterns
the parameter is type C in trait SetOps but the prefix Set1[A](Set1.this)
does not define any corresponding arguments.
	at dotty.tools.dotc.core.Types$NamedType.argDenot(Types.scala:1832)
	at dotty.tools.dotc.core.Types$NamedType.fromDesignator$1(Types.scala:1749)
	at dotty.tools.dotc.core.Types$NamedType.computeDenot(Types.scala:1767)
	at dotty.tools.dotc.core.Types$NamedType.denot(Types.scala:1723)
	at dotty.tools.dotc.core.Types$NamedType.info(Types.scala:1712)
	at dotty.tools.dotc.core.Types$TermLambda$$anon$8.apply(Types.scala:2826)
	at dotty.tools.dotc.core.Types$TermLambda$$anon$8.apply(Types.scala:2818)
	at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$depStatus(Types.scala:2836)
	at dotty.tools.dotc.core.Types$TermLambda.dependencyStatus(Types.scala:2850)
	at dotty.tools.dotc.core.Types$TermLambda.resultType(Types.scala:2793)
	at dotty.tools.dotc.core.Types$TermLambda.resultType$(Types.scala:2792)
	at dotty.tools.dotc.core.Types$MethodType.resultType(Types.scala:2897)
	at dotty.tools.dotc.core.Types$MethodicType.resultSignature(Types.scala:2622)
	at dotty.tools.dotc.core.Types$MethodicType.resultSignature$(Types.scala:2622)
	at dotty.tools.dotc.core.Types$MethodOrPoly.resultSignature(Types.scala:2765)
	at dotty.tools.dotc.core.Types$MethodType.computeSignature(Types.scala:2917)
	at dotty.tools.dotc.core.Types$SignatureCachingType.signature(Types.scala:2614)
	at dotty.tools.dotc.core.Types$SignatureCachingType.signature$(Types.scala:2612)
	at dotty.tools.dotc.core.Types$MethodOrPoly.signature(Types.scala:2765)
	at dotty.tools.dotc.core.TypeComparer.compareMethod$1(TypeComparer.scala:538)
	at dotty.tools.dotc.core.TypeComparer.thirdTry$1(TypeComparer.scala:544)
	at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:368)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:290)
	at dotty.tools.dotc.core.TypeComparer.$anonfun$recur$2(TypeComparer.scala:873)
	at scala.runtime.java8.JFunction0$mcZ$sp.apply(JFunction0$mcZ$sp.java:12)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:40)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:44)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:133)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:124)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:131)
	at dotty.tools.dotc.core.ConstraintHandling.isSubTypeWhenFrozen(ConstraintHandling.scala:173)
	at dotty.tools.dotc.core.ConstraintHandling.isSubTypeWhenFrozen$(ConstraintHandling.scala:170)
	at dotty.tools.dotc.core.TypeComparer.isSubTypeWhenFrozen(TypeComparer.scala:19)
	at dotty.tools.dotc.core.Types$Type.$anonfun$frozen_$less$colon$less$1(Types.scala:807)
	at scala.runtime.java8.JFunction0$mcZ$sp.apply(JFunction0$mcZ$sp.java:12)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.core.Types$Type.frozen_$less$colon$less(Types.scala:807)
	at dotty.tools.dotc.core.Types$Type.overrides(Types.scala:843)
	at dotty.tools.dotc.typer.RefChecks$.$anonfun$checkAllOverrides$52(RefChecks.scala:640)
	at dotty.tools.dotc.typer.RefChecks$.$anonfun$checkAllOverrides$52$adapted(RefChecks.scala:637)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at dotty.tools.dotc.typer.RefChecks$.$anonfun$checkAllOverrides$51(RefChecks.scala:637)
	at dotty.tools.dotc.typer.RefChecks$.$anonfun$checkAllOverrides$51$adapted(RefChecks.scala:636)
	at scala.collection.Iterator.foreach(Iterator.scala:944)
	at scala.collection.Iterator.foreach$(Iterator.scala:944)
	at dotty.tools.dotc.util.HashSet$$anon$1.foreach(HashSet.scala:102)
	at dotty.tools.dotc.util.Set.foreach(Set.scala:17)
	at dotty.tools.dotc.typer.RefChecks$.checkMemberTypesOK$1(RefChecks.scala:636)
	at dotty.tools.dotc.typer.RefChecks$.dotty$tools$dotc$typer$RefChecks$$checkAllOverrides(RefChecks.scala:668)
	at dotty.tools.dotc.typer.RefChecks.transformTemplate(RefChecks.scala:963)
	at dotty.tools.dotc.transform.MegaPhase.goTemplate(MegaPhase.scala:922)
	at dotty.tools.dotc.transform.MegaPhase.goTemplate(MegaPhase.scala:923)

@Blaisorblade
Copy link
Contributor

Oh, #5010, #5027 and scala/bug#11111 overlap/coincide with both issues. Looks like the first one works only because A is not used in the body of Foo?

liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 1, 2019
The code no longer type checks after scala#5027.
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 1, 2019
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 1, 2019
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

2 participants