diff options
| author | Roy Frostig <[email protected]> | 2010-07-19 19:06:55 -0700 |
|---|---|---|
| committer | Roy Frostig <[email protected]> | 2010-07-19 19:06:55 -0700 |
| commit | ae515c017c0aadb2a4c691804f1bc3b8b343dd67 (patch) | |
| tree | 162a9bce32a712db96d45ed20f7c8e2e20355ae3 /src | |
| parent | Autoderef objects when passing them as implicit (indirect) arg upon vtbl-disp... (diff) | |
| download | rust-ae515c017c0aadb2a4c691804f1bc3b8b343dd67.tar.xz rust-ae515c017c0aadb2a4c691804f1bc3b8b343dd67.zip | |
ctxt_auto_deref_lval decides whether to autoderef the entire lval, not its base.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 1 | ||||
| -rw-r--r-- | src/boot/me/trans.ml | 41 | ||||
| -rw-r--r-- | src/test/run-pass/autoderef-full-lval.rs | 18 |
3 files changed, 43 insertions, 17 deletions
diff --git a/src/Makefile b/src/Makefile index adc3ec17..628eab62 100644 --- a/src/Makefile +++ b/src/Makefile @@ -386,6 +386,7 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \ acyclic-unwind.rs \ alt-pattern-simple.rs \ alt-tag.rs \ + autoderef-full-lval.rs \ autoderef-objfn.rs \ basic.rs \ bind-obj-ctor.rs \ diff --git a/src/boot/me/trans.ml b/src/boot/me/trans.ml index d1e707b7..d8128196 100644 --- a/src/boot/me/trans.ml +++ b/src/boot/me/trans.ml @@ -973,33 +973,40 @@ let trans_visitor (lv:Ast.lval) : (Il.cell * Ast.ty) = - let rec trans_slot_lval_full (initializing:bool) lv = + let rec trans_slot_lval_full (initializing:bool) (outermost:bool) lv = let (cell, ty) = match lv with Ast.LVAL_ext (base, comp) -> let (base_cell, base_ty) = - trans_slot_lval_full initializing base + trans_slot_lval_full initializing false base in trans_slot_lval_ext initializing base_ty base_cell comp - | Ast.LVAL_base nbi -> + | Ast.LVAL_base _ -> let sloti = lval_base_to_slot cx lv in let cell = cell_of_block_slot sloti.id in let ty = slot_ty sloti.node in let cell = deref_slot initializing cell sloti.node in - let dctrl = - (* If this fails, type didn't visit the lval, and we - * don't know whether to auto-deref its base. Crashing - * here is best. Compiler bug. - *) - match htab_search cx.ctxt_auto_deref_lval nbi.id with - None -> - bugi cx nbi.id - "Lval without auto-deref info; bad typecheck?" - | Some true -> DEREF_all_boxes - | Some false -> DEREF_none - in - deref_ty dctrl initializing cell ty + (cell, ty) + in + let (cell, ty) = + if outermost + then + let id = lval_base_id lv in + let dctrl = + (* If this fails, type didn't visit the lval, and we + * don't know whether to auto-deref the entire lval. + * Crashing here is best. Compiler bug. + *) + match htab_search cx.ctxt_auto_deref_lval id with + None -> + bugi cx id + "Lval without auto-deref info; bad typecheck?" + | Some true -> DEREF_all_boxes + | Some false -> DEREF_none + in + deref_ty dctrl initializing cell ty + else (cell, ty) in iflog begin @@ -1013,7 +1020,7 @@ let trans_visitor in if lval_is_slot cx lv - then trans_slot_lval_full initializing lv + then trans_slot_lval_full initializing true lv else if initializing then err None "init item" diff --git a/src/test/run-pass/autoderef-full-lval.rs b/src/test/run-pass/autoderef-full-lval.rs new file mode 100644 index 00000000..956a7eb4 --- /dev/null +++ b/src/test/run-pass/autoderef-full-lval.rs @@ -0,0 +1,18 @@ +// -*- rust -*- + +type clam = rec(@int x, @int y); +type fish = tup(@int); + +fn main() { + let clam a = rec(x=@1, y=@2); + let clam b = rec(x=@10, y=@20); + let int z = a.x + b.y; + log z; + check (z == 21); + + let fish forty = tup(@40); + let fish two = tup(@2); + let int answer = forty._0 + two._0; + log answer; + check (answer == 42); +} |