Skip to content

Commit 3a03879

Browse files
committed
Motivate <<- behaviour
1 parent f54d1b3 commit 3a03879

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

crates/oak_index/src/use_def_map.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ use crate::semantic_index::UseId;
8181
// ### Loop-carried definitions (`finish_loop_defs()`)
8282
//
8383
// ```r
84-
// x <- 0
84+
// x <- 0 # def A
8585
// while (cond) {
8686
// print(x) # should see def A (pre-loop) AND def B (previous iteration)
8787
// x <- 1 # def B
@@ -97,6 +97,12 @@ use crate::semantic_index::UseId;
9797
//
9898
// ### Deferred definitions (`record_deferred_definition()`)
9999
//
100+
// `<<-` modifies a symbol that should already be bound in an ancestor scope (if
101+
// there is no existing definition, R stores in the global environment, but
102+
// we'll lint about it). For this reason, `<<-` _adds_ to the set of potential
103+
// definitions reaching uses of that symbols, it doesn't overwrite like `<-`
104+
// would.
105+
//
100106
// ```r
101107
// x <- 0 # def A
102108
// print(x) # should see def A AND def B
@@ -105,7 +111,7 @@ use crate::semantic_index::UseId;
105111
// }
106112
// ```
107113
//
108-
// The `<<-` creates a definition in the file scope, but it's encountered
114+
// Here the `<<-` creates a definition in the file scope, but it's encountered
109115
// during the function body walk, after `print(x)` was already recorded.
110116
// `record_deferred_definition()` adds it to the live state (so future uses
111117
// see it) and also stashes it. At finalization, `finish_deferred_defs()`

0 commit comments

Comments
 (0)