-
Notifications
You must be signed in to change notification settings - Fork 364
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
fix: addressability #2731
Open
deelawn
wants to merge
40
commits into
gnolang:master
Choose a base branch
from
deelawn:fix/addressability
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: addressability #2731
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
c8462ec
preprocessor addressability work
deelawn ef97274
fix selector isaddressable
deelawn 7fa9f50
fix starexpr isaddressable
deelawn 08563c3
fix sliceexpr addressability
deelawn 3b78ae9
fix typeassertexpr addressability
deelawn a0e13b9
fix callexpr addressable return types
deelawn ae55b84
mark append and new results as addressable
deelawn 990017d
fix selector addressability
deelawn 3621dc7
make string indexes non-addressable
deelawn 9faf3df
addressability file tests
deelawn 8671ea5
prohibit taking address of imported typed constant
deelawn 816dbd6
more tests
deelawn 77caea9
fix type assertion addressability and add tests
deelawn 89a041c
make sure to use base types when considering addressability
deelawn 9956c26
move tests
deelawn 6940714
fix index and selector addressability
deelawn 3f4f1b6
introduce concept of addressability not applicable
deelawn c16e5e9
fixed test
deelawn ac79f00
fixed test
deelawn df764cd
fix test
deelawn af12ca1
func lit tests
deelawn e498f1c
index, map, and call expr fixes and tests
deelawn bee868c
addressability consistentcy fixes
deelawn 9698461
consolidate simplest block path traversal
deelawn b284b56
fix comment
deelawn dfe024f
Removed test and renamed other
deelawn 0e80801
move and rename addressability constants
deelawn 804c17e
remove assertExpr
deelawn 44cc298
clarifying comment
deelawn 548af87
fixed comment
deelawn 8bec242
panic when calling addressability on type expressions
deelawn 8fe3b37
fixed tesst
deelawn 26e8529
added comment
deelawn 3c120ae
Merge branch 'master' into fix/addressability
deelawn feee13d
fixed test
deelawn b33f0b0
fix double reference addressability and add comments
deelawn a8827ff
fixed test
deelawn 71afb10
corrected double ref addressability check
deelawn 2fc5c88
fixed star expression addressability
deelawn eddcd54
added comment
deelawn 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,38 @@ | ||
package main | ||
|
||
func main() { | ||
// Array pointers are addressable. | ||
println(&getArrPtr1()[0]) | ||
println(&getArrPtr2()[0]) | ||
println(&getArrPtr3()[0]) | ||
println(&new([1]int)[0]) | ||
|
||
// Array pointers are slicable. | ||
println(getArrPtr1()[:]) | ||
println(getArrPtr2()[:]) | ||
println(getArrPtr3()[:]) | ||
println(new([1]int)[:]) | ||
} | ||
|
||
func getArrPtr1() *[1]int { | ||
return &[1]int{1} | ||
} | ||
|
||
func getArrPtr2() *[1]int { | ||
a := [1]int{2} | ||
return &a | ||
} | ||
|
||
func getArrPtr3() *[1]int { | ||
return new([1]int) | ||
} | ||
|
||
// Output: | ||
// &(1 int) | ||
// &(2 int) | ||
// &(0 int) | ||
// &(0 int) | ||
// slice[(1 int)] | ||
// slice[(2 int)] | ||
// slice[(0 int)] | ||
// slice[(0 int)] |
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,12 @@ | ||
package main | ||
|
||
type S struct { | ||
i int | ||
} | ||
|
||
func main() { | ||
println(&new(S).i) | ||
} | ||
|
||
// Output: | ||
// &(0 int) |
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,14 @@ | ||
package main | ||
|
||
func main() { | ||
println(&getPtr()) | ||
} | ||
|
||
type S struct{} | ||
|
||
func getPtr() *S { | ||
return &S{} | ||
} | ||
|
||
// Error: | ||
// main/files/addressable_10a_err.gno:4:10: cannot take address of getPtr<VPBlock(3,2)>() |
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,12 @@ | ||
package main | ||
|
||
type S struct { | ||
i int | ||
} | ||
|
||
func main() { | ||
println(&new(S)) | ||
} | ||
|
||
// Error: | ||
// main/files/addressable_10b_err.gno:8:10: cannot take address of (const (new func(t type{})( *main.S)))(S<VPBlock(3,0)>) |
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,39 @@ | ||
package main | ||
|
||
func main() { | ||
var ii **int | ||
i := new(int) | ||
ii = &i | ||
println(&(*ii)) | ||
println(&ii) | ||
println(i) | ||
println(ii) | ||
println(&i) | ||
|
||
j := new(int) | ||
println(&(*j)) | ||
|
||
println(&(*getPtr())) | ||
|
||
derefTypeAssert() | ||
} | ||
|
||
func getPtr() *int { | ||
return new(int) | ||
} | ||
|
||
func derefTypeAssert() { | ||
var i interface{} | ||
i = new(int) | ||
println(&(*(i.(*int)))) | ||
} | ||
|
||
// Output: | ||
// &(&(0 int) *int) | ||
// &(&(&(0 int) *int) **int) | ||
// &(0 int) | ||
// &(&(0 int) *int) | ||
// &(&(0 int) *int) | ||
// &(0 int) | ||
// &(0 int) | ||
// &(0 int) |
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 @@ | ||
package main | ||
|
||
func main() { | ||
_ = &[1]int{1}[0] | ||
} | ||
|
||
// Error: | ||
// main/files/addressable_1a_err.gno:4:6: cannot take address of [(const (1 int))](const-type int){(const (1 int))}[(const (0 int))] |
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 @@ | ||
package main | ||
|
||
func main() { | ||
_ = [1]int{1}[:] | ||
} | ||
|
||
// Error: | ||
// main/files/addressable_1b_err.gno:4:6: cannot take address of [(const (1 int))](const-type int){(const (1 int))} |
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,13 @@ | ||
package main | ||
|
||
func main() { | ||
_ = &getArr()[0] | ||
} | ||
|
||
func getArr() [1]int { | ||
arr := [1]int{1} | ||
return arr | ||
} | ||
|
||
// Error: | ||
// main/files/addressable_1c_err.gno:4:6: cannot take address of getArr<VPBlock(3,1)>()[(const (0 int))] |
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,12 @@ | ||
package main | ||
|
||
func main() { | ||
_ = getArr()[:] | ||
} | ||
|
||
func getArr() [1]int { | ||
return [1]int{1} | ||
} | ||
|
||
// Error: | ||
// main/files/addressable_1d_err.gno:4:6: cannot take address of getArr<VPBlock(3,1)>() |
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,40 @@ | ||
package main | ||
|
||
func main() { | ||
// Slices are addressable because the underlying array is addressable | ||
// after slice initialization. | ||
println(&[]int{1}[0]) | ||
println(&getSlice1()[0]) | ||
println(&getSlice2()[0]) | ||
println(&[]int{1}) | ||
|
||
a := []int{1} | ||
println(&append(a, 1, 2, 3, 4, 5)[5]) | ||
|
||
println([]int{1}[:]) | ||
println(getSlice1()[:]) | ||
println(getSlice2()[:]) | ||
|
||
b := []int{1} | ||
println(append(b, 1, 2, 3, 4, 5)[:]) | ||
} | ||
|
||
func getSlice1() []int { | ||
return []int{2} | ||
} | ||
|
||
func getSlice2() []int { | ||
s := []int{3} | ||
return s | ||
} | ||
|
||
// Output: | ||
// &(1 int) | ||
// &(2 int) | ||
// &(3 int) | ||
// &(slice[(1 int)] []int) | ||
// &(5 int) | ||
// slice[(1 int)] | ||
// slice[(2 int)] | ||
// slice[(3 int)] | ||
// slice[(1 int),(1 int),(2 int),(3 int),(4 int),(5 int)] |
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 @@ | ||
package main | ||
|
||
func main() { | ||
_ = &[]int{1}[:] | ||
} | ||
|
||
// Error: | ||
// main/files/addressable_2a_err.gno:4:6: cannot take address of [](const-type int){(const (1 int))}[:] |
Oops, something went wrong.
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.
an explanatory comment?
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.
Added a comment here eddcd54