-
Notifications
You must be signed in to change notification settings - Fork 3.1k
SI-4700 Types with symbolic names print in infix by default #5589
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
Conversation
``` scala> import scala.annotation.infix import scala.annotation.infix scala> @infix class &&[T, U] defined class $amp$amp scala> def foo: Int && Boolean = ??? foo: Int && Boolean ```
Thanks @allisonhb for picking this up, it looks great in the current form! CC @adriaanm However, it adds a public class to the standard library, which is not forwards binary compatible. @SethTisue do you know why this is not flagged by MiMa? Could we ignore this case? |
I we fixed a MiMa bug recently in our build. If this PR were rebased on 2.12.x, the compat violation ought to be reported. I'm not totally against the idea of allowing annotations in a minor release. Need to give it some thought. Last time we considered this was with |
So for what little it's worth, I can't think of any places where someone would rather keep the prefix notation for symbolic type names, and only a few (refined comes to mind) where infix notation is preferred for non-symbolic names. On the other hand, I know that at least in my workplace, types such as --allison edit: woops accidentally pushed "close + commit" button... |
@allisonhb I'd be very keen to merge this in Typelevel Scala for the upcoming 2.12.1 release ... please let me know if you'd be happy with that. |
@milessabin that sounds great! I'll make a PR against TLS as soon as I get home. |
@allisonhb no need ... I can merge this PR to TLS as it stands. Thanks for working on this! |
/* It only makes sense to show 2-ary type constructors infix. | ||
* By default we do only if it's a symbolic name. */ | ||
override def isShowAsInfixType: Boolean = | ||
args.size == 2 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's best to avoid calling size
on a list. We have a more performant convenience method for this: hasLength(args, 2)
Add ability to disable this via the @showAsInfix annotation.
I did some testing what will happen if a class annotated
so this seems to be safe. |
LGTM, veto by @retronym? |
Not sure about the details of the code, but I definitely support this design change. |
FYI: this has been merged in Typelevel Scala 2.12.1. |
Based on Lukas's testing, I think this is ready to go. |
little missing piece of scala#5589; not sure why it didn't fail PR validation
little missing piece of scala#5589
we get failures in the
|
looks like the tags of the actual scaladocs did change with this. Was that expected? |
I hadn't expected that, no! Could you file a bug at scala/bug?
…On Wed, Apr 19, 2017 at 12:04 Sam Halliday ***@***.***> wrote:
looks like the tags of the actual scaladocs did change with this. Was that
expected?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#5589 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAFjy-dvWwGUlUVCJjREm1jiE4wzOUGmks5rxj5_gaJpZM4LHYgz>
.
|
@adriaanm I'm not sure if it is a bug, it's a regression if anything, but flip flopping on regressions is not great either |
@allisonhb since this PR is linked directly from the 2.12.2 release notes, I've edited your PR description to include a "before/after" pair |
This a partial port of scala/scala#5589 to dotty: when pretty-printing an applied type, if its type constructor has a symbolic name, then always print it in infix form. The PR in scalac also adds an `@showAsInfix` annotation to control this behavior, but we cannot do the same in dotty since we still rely on the standard library from Scala 2.11 and the annotation only exists in 2.12 and up.
Would be really nice if types would display accordingly in the scaladoc output. |
I'd settle for scalac providing utility methods that converted between all the different kinds of names that a thing can have. This is the bulk of our work interfacing with the interactive compiler in ensime. |
that would make a great scala/bug ticket (if there isn't one already?), and a nice manageably sized issue, I expect, for a volunteer contributor to tackle was thinking of this just now because I'm watching a talk where the speaker is demoing |
before:
after:
Building off of @VladUreche's work in #5401, here's a PR that addresses some of the comments there.
@showAsInfix
annotation to enable/disable override that for types.Review by @lrytz, @retronym, and others?
--allison