-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Better error message when accessing private members #18690
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- [E173] Reference Error: tests/neg/i18686.scala:13:16 ---------------------------------------------------------------- | ||
13 | println(Foo.Bar1) // error | ||
| ^^^^^^^^ | ||
| value Bar1 cannot be accessed as a member of Foo.type from object Main. | ||
| private value Bar1 can only be accessed from object Foo. | ||
-- [E173] Reference Error: tests/neg/i18686.scala:14:16 ---------------------------------------------------------------- | ||
14 | println(Foo.Bar2) // error | ||
| ^^^^^^^^ | ||
| value Bar2 cannot be accessed as a member of Foo.type from object Main. | ||
| private[Foo] value Bar2 can only be accessed from object Foo. | ||
-- [E173] Reference Error: tests/neg/i18686.scala:15:16 ---------------------------------------------------------------- | ||
15 | println(Foo.Bar3) // error | ||
| ^^^^^^^^ | ||
| value Bar3 cannot be accessed as a member of Foo.type from object Main. | ||
| protected value Bar3 can only be accessed from object Foo. | ||
-- [E173] Reference Error: tests/neg/i18686.scala:16:16 ---------------------------------------------------------------- | ||
16 | println(Foo.Bar4) // error | ||
| ^^^^^^^^ | ||
| value Bar4 cannot be accessed as a member of Foo.type from object Main. | ||
| protected[Foo] value Bar4 can only be accessed from object Foo. | ||
-- [E173] Reference Error: tests/neg/i18686.scala:17:20 ---------------------------------------------------------------- | ||
17 | println(Foo.Baz.Bar5) // error | ||
| ^^^^^^^^^^^^ | ||
| value Bar5 cannot be accessed as a member of Foo.Baz.type from object Main. | ||
| private[Foo] value Bar5 can only be accessed from object Foo. | ||
-- [E173] Reference Error: tests/neg/i18686.scala:18:20 ---------------------------------------------------------------- | ||
18 | println(Foo.Baz.Bar6) // error | ||
| ^^^^^^^^^^^^ | ||
| value Bar6 cannot be accessed as a member of Foo.Baz.type from object Main. | ||
| protected[Foo] value Bar6 can only be accessed from object Foo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
object Foo: | ||
private val Bar1: Int = 1 | ||
private[Foo] val Bar2: Int = 2 | ||
protected val Bar3: Int = 3 | ||
protected[Foo] val Bar4: Int = 5 | ||
object Baz: | ||
private[Foo] val Bar5: Int = 5 | ||
protected[Foo] val Bar6: Int = 6 | ||
end Foo | ||
|
||
object Main: | ||
def main(args: Array[String]): Unit = | ||
println(Foo.Bar1) // error | ||
println(Foo.Bar2) // error | ||
println(Foo.Bar3) // error | ||
println(Foo.Bar4) // error | ||
println(Foo.Baz.Bar5) // error | ||
println(Foo.Baz.Bar6) // error | ||
end main | ||
end Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- [E173] Reference Error: tests/neg/i18686b.scala:15:16 --------------------------------------------------------------- | ||
15 | println(foo.Bar1) // error | ||
| ^^^^^^^^ | ||
| value Bar1 cannot be accessed as a member of Foo from object Main. | ||
| private value Bar1 can only be accessed from class Foo. | ||
-- [E173] Reference Error: tests/neg/i18686b.scala:16:16 --------------------------------------------------------------- | ||
16 | println(foo.Bar2) // error | ||
| ^^^^^^^^ | ||
| value Bar2 cannot be accessed as a member of Foo from object Main. | ||
| private[Foo] value Bar2 can only be accessed from class Foo. | ||
-- [E173] Reference Error: tests/neg/i18686b.scala:17:16 --------------------------------------------------------------- | ||
17 | println(foo.Bar3) // error | ||
| ^^^^^^^^ | ||
| value Bar3 cannot be accessed as a member of Foo from object Main. | ||
| protected value Bar3 can only be accessed from class Foo or one of its subclasses. | ||
-- [E173] Reference Error: tests/neg/i18686b.scala:18:16 --------------------------------------------------------------- | ||
18 | println(foo.Bar4) // error | ||
| ^^^^^^^^ | ||
| value Bar4 cannot be accessed as a member of Foo from object Main. | ||
| protected[Foo] value Bar4 can only be accessed from class Foo or one of its subclasses. | ||
-- [E008] Not Found Error: tests/neg/i18686b.scala:19:20 --------------------------------------------------------------- | ||
19 | println(foo.Baz.Bar5) // error | ||
| ^^^^^^^^^^^^ | ||
| value Bar5 is not a member of object Foo#Baz | ||
-- [E008] Not Found Error: tests/neg/i18686b.scala:20:20 --------------------------------------------------------------- | ||
20 | println(foo.Baz.Bar6) // error | ||
| ^^^^^^^^^^^^ | ||
| value Bar6 is not a member of object Foo#Baz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Foo: | ||
private val Bar1: Int = 1 | ||
private[Foo] val Bar2: Int = 2 | ||
protected val Bar3: Int = 3 | ||
protected[Foo] val Bar4: Int = 5 | ||
class Baz: | ||
private[Foo] val Bar5: Int = 5 | ||
protected[Foo] val Bar6: Int = 6 | ||
end Foo | ||
|
||
def foo = new Foo | ||
|
||
object Main: | ||
def main(args: Array[String]): Unit = | ||
println(foo.Bar1) // error | ||
println(foo.Bar2) // error | ||
println(foo.Bar3) // error | ||
println(foo.Bar4) // error | ||
println(foo.Baz.Bar5) // error | ||
println(foo.Baz.Bar6) // error | ||
end main | ||
end Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- [E173] Reference Error: tests/neg/i18686c.scala:8:6 ----------------------------------------------------------------- | ||
8 | foo.foo // error | ||
| ^^^^^^^ | ||
|method foo cannot be accessed as a member of (foo² : Bar.Foo) from the top-level definitions in package <empty>. | ||
| protected[Bar] method foo can only be accessed from object Bar, or class Foo in object Bar or one of its subclasses. | ||
| | ||
|where: foo is a method in class Foo | ||
| foo² is a parameter in method test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
object Bar: | ||
class Foo: | ||
protected[Bar] def foo = 23 | ||
class Qux extends Foo: | ||
val qux = foo | ||
|
||
def test(foo: Bar.Foo) = | ||
foo.foo // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice!