Skip to content
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

Interaction of if and for #46

Open
hvesalai opened this issue Feb 19, 2013 · 6 comments
Open

Interaction of if and for #46

hvesalai opened this issue Feb 19, 2013 · 6 comments

Comments

@hvesalai
Copy link
Owner

for {
  j <- js if (j.isSomething)
    i <- j // indented incorrectly because of "if ()"
} yield i 
@taku0
Copy link

taku0 commented Apr 21, 2013

The problem does not reproduced with the version 20130403.1734.

Assignments with tuple patterns without val keywords are still indented incorrectly after parenthesis.

for {
  a <- as()
         (b, c) = a
} {
  println((b, c))
}

for {
  a <- as()
  if f(a)
      (b, c) = a
} {
  println((b, c))
}

@hvesalai
Copy link
Owner Author

It's worse

for {
  i <- (1 to j)
  if (doo)
    } yield i // indents very badly

@hvesalai
Copy link
Owner Author

As for the

for {
  a <- as()
         (b, c) = a

The language specification seems to say it's invalid. See section 6.19 in http://www.scala-lang.org/docu/files/ScalaReference.pdf

It seems to say, the val keyword is required for the assignment expression.

@taku0
Copy link

taku0 commented Apr 22, 2013

Though ScalaReference.pdf is not updated, val keyword in for comprehension is deprecated in 2.10.

Example:

scala -deprecation -e 'for {a <- 1.until(10); val b = a * a} {println(b)}'

Output (Scala 2.10.0):

/var/folders/jt/vt_r044j597g0j9txyfhc8n40000gn/T/scalacmd396058998360302477.scala:1: warning: val keyword in for comprehension is deprecated
for {a <- 1.until(10); val b = a * a} {println(b)}
                             ^
one warning found
1
4
9
16
25
36
49
64
81

@SethTisue
Copy link
Contributor

right. re: the antiquated spec, see https://issues.scala-lang.org/browse/SI-4918

@hvesalai
Copy link
Owner Author

Oh how I wish somebody would update the spec.

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

No branches or pull requests

3 participants