Skip to content

Add colon after method type in printer #1705

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
wants to merge 1 commit into from
Closed

Conversation

rethab
Copy link
Contributor

@rethab rethab commented Nov 13, 2016

Changes

scala> def id(x: 4): 4 = x
id: (x: Int(4))Int(4)

to

scala> def id(x: 4): 4 = x
id: (x: Int(4)): Int(4)

Contrary to the github markdown, the REPL would not highlight the method type w/o this change.

@Blaisorblade
Copy link
Contributor

Blaisorblade commented Nov 13, 2016

Hi and thanks for the PR! If I may comment as an outsider, I think the type syntax itself is intended, and is even described in the language spec (http://scala-lang.org/files/archive/spec/2.12/03-types.html#method-types); maybe the highlighting should be changed.
The syntax for method types is hard to see, because they aren't value types (again see the spec) and IIUC can't appear in code as types of some value.

Your example doesn't work in Scala 2, but a variant does and gives a colon-less output in both REPLs. I can confirm that the Int in (x: Int)Int is not highlighted and that seems a bug.

scala> def id(x: Int): Int = x
id: (x: Int)Int

@smarter
Copy link
Member

smarter commented Nov 13, 2016

I think we should just print it like this:

scala> def id(x: Int): Int = x
def id(x: Int): Int

Anything else is confusing for users.

@smarter
Copy link
Member

smarter commented Nov 13, 2016

...which is exactly what scala/scala#5498 is about

@rethab
Copy link
Contributor Author

rethab commented Nov 13, 2016

@Blaisorblade thanks for reference to the spec and your comments. That would mean we're simply missing the space. I just tested that and if there is a space, then the higlighting works correctly (the colon is not necessary for that).

@smarter consequently, should the same thing apply for vals? vars?

@smarter
Copy link
Member

smarter commented Nov 13, 2016

@smarter consequently, should the same thing apply for vals? vars?

Yes.

@rethab rethab force-pushed the master branch 4 times, most recently from d892fc0 to 9c6fe7d Compare November 15, 2016 06:09
@odersky odersky self-assigned this Nov 16, 2016
@rethab rethab force-pushed the master branch 2 times, most recently from bd7a059 to dc71872 Compare November 20, 2016 16:13
@rethab
Copy link
Contributor Author

rethab commented Nov 20, 2016

I have updated the code to print the following:

scala> def id(x: Int): Int = 10
def id: (x: Int): Int
scala> def idi(x: Int)(implicit y: Int): Int = x + y
def idi: (x: Int)(implicit y: Int): Int
scala> val a: Int = 10
val a: Int = 10
scala> var b: Int = 10
var b: Int = 10

@smarter What do you think?

@smarter
Copy link
Member

smarter commented Nov 20, 2016

Looks nice! I think I would go further and print def id(x: Int): Int instead of def id: (x: Int): Int

@rethab
Copy link
Contributor Author

rethab commented Nov 20, 2016

@smarter sorry I missed that in your example above. Fixed now!

@smarter
Copy link
Member

smarter commented Nov 20, 2016

As the test failures indicate, you need to update the check files in https://github.com/lampepfl/dotty/tree/master/tests/repl to the new format (you can run just these tests locally using test-only -- --tests=repl_all from sbt)

@felixmulder
Copy link
Contributor

Completed in #1742, thanks @rethab !

odersky referenced this pull request Nov 24, 2016
Fix #1707: Survive non-existing positions in parser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants