Skip to content

Fix #1959: infix type operators in the REPL #2162

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

Merged
merged 1 commit into from
Apr 4, 2017
Merged

Conversation

abeln
Copy link
Contributor

@abeln abeln commented Mar 31, 2017

Infix type operators were broken in the REPL.
The REPL uses fold methods from the untpd package,
but those were skipping the operator subtree when folding
over an InfixOp.

Fix the issue by taking the operator into account.

Tested:

  1. Verified that only the REPL code uses the modified
    fold method.
  2. The following interaction now works in the REPL
    (used to fail with a 'can't find +' error):

scala> class +[A, B](a: A, B: B)
defined class +
scala> type IntAndString = Int + String
defined type alias IntAndString
scala> new IntAndString(42, "hello world")
val res0: +[Int, String] = $plus@6a472554

@abeln abeln changed the title Fix https://github.com/lampepfl/dotty/issues/1959 Fix #1959: infix type operators in the REPL Mar 31, 2017
@abeln
Copy link
Contributor Author

abeln commented Mar 31, 2017

This fixes #1959.

@DarkDimius
Copy link
Contributor

@abeln, thank you for your contribution, would you please edit commit message to start with
"Fix #1959: "? It helps a lot when navigating commit history in github.

@DarkDimius
Copy link
Contributor

Would you also kindly include a test to repl tests that would track that the issue stays fixed?

@smarter
Copy link
Member

smarter commented Mar 31, 2017

@abeln Nice catch! Would you mind adding a REPL test? It's pretty easy, you just need to add a file in https://github.com/lampepfl/dotty/tree/master/tests/repl which contains the output of a REPL session.

@abeln abeln force-pushed the infix-op branch 2 times, most recently from 7a00823 to f225d02 Compare March 31, 2017 14:38
@abeln
Copy link
Contributor Author

abeln commented Mar 31, 2017

PTAL -- added repl test
thanks for the prompt review!

@DarkDimius
Copy link
Contributor

@abeln, thank you for your contribution, would you please edit commit message to start with
"Fix #1959: "? It helps a lot when navigating commit history in github.

@abeln, could you please update commit message?

@abeln
Copy link
Contributor Author

abeln commented Mar 31, 2017

@DarkDimius oops, sorry -- I'd changed the PR title, but forgot the commit title. PTAL.

@@ -526,7 +526,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
case Function(args, body) =>
this(this(x, args), body)
case InfixOp(left, op, right) =>
this(this(x, left), right)
this(this(this(x, left), op), right)
case PostfixOp(od, op) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked how UntypedTreeAccumulator is used exactly, but if InfixOp folds over the op, then surely PostfixOp and PrefixOp should too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UntypedTreeAccumulator (and its cousing UntypedDeepFolder) is used only in the repl code (CompilingInterpreter.scala).
Changed {Post, Pre}fixOp as well.
PTAL.

Infix type operators were broken in the REPL.
The REPL uses fold methods from the untpd package,
but those were skipping the operator subtree when folding
over an InfixOp.

Fix the issue by taking the operator into account.

Tested:
1) Verified that only the REPL code uses the modified
fold method.
2) Added repl test.
@abeln
Copy link
Contributor Author

abeln commented Apr 3, 2017

@DarkDimius friendly ping :)

Copy link
Contributor

@DarkDimius DarkDimius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM, thanks for the contribution!

case PrefixOp(op, od) =>
this(x, od)
this(this(x, op), od)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to expand the test to also test this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Dotty have prefix type operators? If so, how are they used?
"Regular" prefix operators already worked in the REPL before this change: it's a different ast that doesn't end up using the code above.

This is the hypothetical test I'd add, but like I said it's not really exercising this PR.

scala> class B(val n: Int) {
def unary_! = new B(-n)
}
defined class B
scala> val x = new B(42)
val x: B = B@10e92f8f
scala> (!x).n
val res4: Int = -42

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. Let's get this in.

@DarkDimius DarkDimius merged commit a71cb97 into scala:master Apr 4, 2017
@felixmulder
Copy link
Contributor

Thanks for the contribution! 🎉

@abeln abeln deleted the infix-op branch April 4, 2017 11:32
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.

4 participants