|
| 1 | +-- [E049] Reference Error: tests/neg/i12682.scala:6:12 ----------------------------------------------------------------- |
| 2 | +6 | val x = m(1) // error |
| 3 | + | ^ |
| 4 | + | Reference to m is ambiguous. |
| 5 | + | It is both defined in object C |
| 6 | + | and inherited subsequently in object T |
| 7 | + |--------------------------------------------------------------------------------------------------------------------- |
| 8 | + | Explanation (enabled by `-explain`) |
| 9 | + |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 10 | + | The identifier m is ambiguous because a name binding of lower precedence |
| 11 | + | in an inner scope cannot shadow a binding with higher precedence in |
| 12 | + | an outer scope. |
| 13 | + | |
| 14 | + | The precedence of the different kinds of name bindings, from highest to lowest, is: |
| 15 | + | - Definitions in an enclosing scope |
| 16 | + | - Inherited definitions and top-level definitions in packages |
| 17 | + | - Names introduced by import of a specific name |
| 18 | + | - Names introduced by wildcard import |
| 19 | + | - Definitions from packages in other files |
| 20 | + | Note: |
| 21 | + | - As a rule, definitions take precedence over imports. |
| 22 | + | - Definitions in an enclosing scope take precedence over inherited definitions, |
| 23 | + | which can result in ambiguities in nested classes. |
| 24 | + | - When importing, you can avoid naming conflicts by renaming: |
| 25 | + | import scala.{m => mTick} |
| 26 | + --------------------------------------------------------------------------------------------------------------------- |
| 27 | +-- [E049] Reference Error: tests/neg/i12682.scala:13:10 ---------------------------------------------------------------- |
| 28 | +13 | def d = m(42) // error |
| 29 | + | ^ |
| 30 | + | Reference to m is ambiguous. |
| 31 | + | It is both imported by import X._ |
| 32 | + | and imported subsequently by import Y._ |
| 33 | + |-------------------------------------------------------------------------------------------------------------------- |
| 34 | + | Explanation (enabled by `-explain`) |
| 35 | + |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 36 | + | The identifier m is ambiguous because two name bindings of equal precedence |
| 37 | + | were introduced in the same scope. |
| 38 | + | |
| 39 | + | The precedence of the different kinds of name bindings, from highest to lowest, is: |
| 40 | + | - Definitions in an enclosing scope |
| 41 | + | - Inherited definitions and top-level definitions in packages |
| 42 | + | - Names introduced by import of a specific name |
| 43 | + | - Names introduced by wildcard import |
| 44 | + | - Definitions from packages in other files |
| 45 | + | Note: |
| 46 | + | - As a rule, definitions take precedence over imports. |
| 47 | + | - Definitions in an enclosing scope take precedence over inherited definitions, |
| 48 | + | which can result in ambiguities in nested classes. |
| 49 | + | - When importing, you can avoid naming conflicts by renaming: |
| 50 | + | import scala.{m => mTick} |
| 51 | + -------------------------------------------------------------------------------------------------------------------- |
0 commit comments