Skip to content

Commit 16cb974

Browse files
committed
Add tests
1 parent c2d782e commit 16cb974

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
layout: doc-page
3+
title: "Implied Imports"
4+
---
5+
6+
A special form of import is used to import implied instances. Example:
7+
```scala
8+
object A {
9+
class TC
10+
implied tc for TC
11+
def f given TC = ???
12+
}
13+
object B {
14+
import A._
15+
import implied A._
16+
}
17+
```
18+
In the code above, the `import A._` clause of object `B` will import all members
19+
of `A` _except_ the implied instance `tc`. Conversely, the second import `import implied A._` will import _only_ that implied instance.
20+
21+
Generally, a normal import clause brings all definitions except implied instances into scope whereas an `import implied` clause beings only implied instances into scope.
22+
23+
There are two main benefits arising from these rules:
24+
25+
- It is made clearer where implied instances in scope are coming from. In particular, it is not possible to hide imported implied instances in a long list of regular imports.
26+
- It enables importing all implied instances
27+
without importing anything else. This is particularly important since implied
28+
instances can be anonymous, so the usual recourse of using named imports is not
29+
practical.

tests/neg/import-implied.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class TC
2+
object A {
3+
implied tc for TC
4+
def foo given TC = ()
5+
}
6+
object B {
7+
import A._
8+
foo // error: no implicit argument was found
9+
foo given tc // error: not found: tc
10+
foo given A.tc // ok
11+
}
12+
object C {
13+
import A._
14+
import implied A.tc
15+
foo // ok
16+
foo given tc // ok
17+
}
18+
object D {
19+
import A.foo
20+
import implied A._
21+
foo // ok
22+
foo given tc // ok
23+
}
24+
object E {
25+
import A._
26+
import implied A._
27+
foo // ok
28+
foo given tc // ok
29+
}

0 commit comments

Comments
 (0)