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

warning: a pure expression does nothing in statement position #151

Closed
vlovgr opened this issue Feb 7, 2019 · 4 comments
Closed

warning: a pure expression does nothing in statement position #151

vlovgr opened this issue Feb 7, 2019 · 4 comments
Labels

Comments

@vlovgr
Copy link
Contributor

vlovgr commented Feb 7, 2019

The following markdown document:

```scala mdoc
final case class Test(value: Int)

val test = Test(123)

test.value
```

```scala mdoc:fail
val x: Int = "123"
```

yields the following output with mdoc:

```scala
final case class Test(value: Int)

val test = Test(123)
// test: Test = Test(123)

test.value
// res0: Int = 123
```

```scala
val x: Int = "123"
// warning: a pure expression does nothing in statement position; multiline     expressions may require enclosing parentheses
// test.value
// ^^^^^^^^^^
// error: type mismatch;
//  found   : String("123")
//  required: Int
// val x: Int = "123"
//              ^^^^^
```

where the following warning is unexpected.

warning: a pure expression does nothing in statement position; multiline     expressions may require enclosing parentheses
test.value
^^^^^^^^^^
@olafurpg
Copy link
Member

olafurpg commented Feb 8, 2019

Thanks for reporting! This issue is caused by the different compilation encoding used for :fail fences and default fences. In default fences, every statement is bound to a variable like

val res0 = test.value

avoiding the error. We should do the same transformation for non-:fail blocks.

@olafurpg
Copy link
Member

olafurpg commented Feb 8, 2019

Alternatively, we could filter out diagnostics that don't point to the :fail block, that might be simpler but risks hiding useful errors.

@olafurpg olafurpg added the bug label Feb 21, 2019
@olafurpg
Copy link
Member

Pending fix in #154

@olafurpg
Copy link
Member

We still report errors from non-fail blocks but ignore warnings unless they origin from the fail block.

olafurpg added a commit that referenced this issue Feb 21, 2019
Filter out non-section warnings in fail blocks, fixes #151.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants