Skip to content

param accessors should drop @ Repeated from the type. #619

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
retronym opened this issue May 29, 2015 · 4 comments
Closed

param accessors should drop @ Repeated from the type. #619

retronym opened this issue May 29, 2015 · 4 comments

Comments

@retronym
Copy link
Member

cat sandbox/test.scala
class C(val f: Any*) {
  def g = f
}

class Test {
  def test1(c: C): Nothing = c.f
  def test2(c: C): Nothing = c.g
}
% scalac sandbox/test.scala
sandbox/test.scala:6: error: type mismatch;
 found   : c.f.type (with underlying type Any*)
 required: Nothing
  def test1(c: C): Nothing = c.f
                               ^
sandbox/test.scala:7: error: type mismatch;
 found   : Seq[Any]
 required: Nothing
  def test2(c: C): Nothing = c.g
                               ^
two errors found

% ./bin/dotc sandbox/test.scala
sandbox/test.scala:6: error: type mismatch:
 found   : scala.collection.Seq[Any] @Repeated(c.f)
 required: Nothing
  def test1(c: C): Nothing = c.f
                               ^
sandbox/test.scala:7: error: type mismatch:
 found   : scala.collection.Seq[Any] @Repeated
 required: Nothing
  def test2(c: C): Nothing = c.g
                               ^
two errors found

I believe that both dotc and scalac are wrong here to give the param accessor the type Any*/ Any @Repeated. Instead, the repeated-ness of the type should be dropped, in the same way that it is when computing the type of the explicity defined accessor g.

Followup from #617, /cc @smarter

@retronym
Copy link
Member Author

Note: By name constructor parameters are not allowed to to have the val modifier (or, equivalently, be used as case class params), otherwise we would need to test that out as well.

@odersky
Copy link
Contributor

odersky commented Feb 10, 2016

I don't see why. @Repeated is an annotation. The type for @Repeated method parameters gets transformed into an ExprType. But I see nothing wrong with leaving the annotation on the Seq type.

@retronym
Copy link
Member Author

Fair enough. I can't really remember raising this ticket :).

What's the meaning of the Repeated annotation? It isn't documented in the dotty codebase AFAICS. Does it have an analog in scalac?

@odersky
Copy link
Contributor

odersky commented Feb 12, 2016

#1080 adds some documentation to Repeated and other classes.

DarkDimius referenced this issue Feb 12, 2016
Document dotty internal Annotations
@odersky odersky closed this as completed Feb 20, 2016
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

3 participants