Skip to content

Commit

Permalink
Merge pull request #2627 from BuckleScript/fix_2352
Browse files Browse the repository at this point in the history
fix #2352
  • Loading branch information
bobzhang committed Mar 15, 2018
2 parents a428630 + e45ab51 commit 4d306ff
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 73 deletions.
2 changes: 1 addition & 1 deletion jscomp/core/bs_conditional_initial.ml
Expand Up @@ -25,7 +25,7 @@

let setup_env () =
#if BS_DEBUG then
Js_config.set_debug_file "gpr_2608_test.ml";
Js_config.set_debug_file "gpr_2352_test.ml";
#end
Lexer.replace_directive_bool "BS" true;
Lexer.replace_directive_string "BS_VERSION" Bs_version.version
Expand Down
36 changes: 17 additions & 19 deletions jscomp/core/lam_compile.ml
Expand Up @@ -832,37 +832,35 @@ and
args = [obj]} as fn;
arg]
->
begin
let obj_block =
compile_lambda {cxt with st = NeedValue; should_return = ReturnFalse} obj
in
let value_block =
compile_lambda {cxt with st = NeedValue; should_return = ReturnFalse} arg
in
let cont block0 block1 obj_code =
begin
let need_value_no_return_cxt = {cxt with st = NeedValue; should_return = ReturnFalse} in
let obj_output = compile_lambda need_value_no_return_cxt obj in
let arg_output = compile_lambda need_value_no_return_cxt arg in
let cont obj_block arg_block obj_code =
Js_output.output_of_block_and_expression st should_return lam
(
match obj_code with
| None -> Ext_list.append block0 block1
| Some obj_code -> Ext_list.append block0 @@ obj_code :: block1
| None -> Ext_list.append obj_block arg_block
| Some obj_code -> Ext_list.append obj_block (obj_code :: arg_block)
)
in
match obj_block, value_block with
| {block = block0; value = Some obj },
{block = block1; value = Some value}
match obj_output, arg_output with
| {block = obj_block; value = Some obj },
{block = arg_block; value = Some value}
->
if Ext_string.ends_with method_name Literals.setter_suffix then
let property =
Lam_methname.translate ~loc @@
String.sub method_name 0
(String.length method_name - Literals.setter_suffix_len) in
Lam_methname.translate ~loc
(String.sub method_name 0
(String.length method_name - Literals.setter_suffix_len)) in
match Js_ast_util.named_expression obj with
| None ->
cont block0 block1 None (E.assign (E.dot obj property) value)
cont obj_block arg_block None
(E.seq (E.assign (E.dot obj property) value) E.unit)
| Some (obj_code, obj)
->
cont block0 block1 (Some obj_code)
(E.assign (E.dot (E.var obj) property) value)
cont obj_block arg_block (Some obj_code)
(E.seq (E.assign (E.dot (E.var obj) property) value) E.unit)
else
compile_lambda cxt
(Lam.apply fn [arg]
Expand Down
1 change: 1 addition & 0 deletions jscomp/test/.depend
Expand Up @@ -301,6 +301,7 @@ gpr_1943_test.cmj : mt.cmj
gpr_1946_test.cmj : ../stdlib/obj.cmj ../runtime/js.cmj
gpr_2250_test.cmj : mt.cmj
gpr_2316_test.cmj : mt.cmj ../runtime/js.cmj
gpr_2352_test.cmj :
gpr_2474.cmj :
gpr_2487.cmj : ../others/belt.cmj
gpr_2503_test.cmj : mt.cmj ../runtime/js.cmj
Expand Down
1 change: 1 addition & 0 deletions jscomp/test/Makefile
Expand Up @@ -243,6 +243,7 @@ OTHERS := test_literals a test_ari test_export2 test_internalOO test_obj_simple_
block_alias_test\
gpr_2608_test\
pipe_syntax\
gpr_2352_test\
# bs_uncurry_test
# needs Lam to get rid of Uncurry arity first
# simple_derive_test
Expand Down
9 changes: 5 additions & 4 deletions jscomp/test/chain_code_test.js
Expand Up @@ -41,10 +41,11 @@ function f4(h, x, y) {
x,
y
];
return h.paint.draw = /* tuple */[
x,
y
];
h.paint.draw = /* tuple */[
x,
y
];
return /* () */0;
}

eq("File \"chain_code_test.ml\", line 28, characters 5-12", 32, ({
Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/class_setter_getter.js
Expand Up @@ -2,7 +2,8 @@


function fff(x) {
return x.height = 2;
x.height = 2;
return /* () */0;
}

function ff(x, z) {
Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/class_type_ffi_test.js
Expand Up @@ -27,7 +27,8 @@ function sum_poly(zero, add, arr) {
}

function test_set(x) {
return x.length = 3;
x.length = 3;
return /* () */0;
}

function f(x) {
Expand Down
31 changes: 16 additions & 15 deletions jscomp/test/demo.js
Expand Up @@ -102,21 +102,22 @@ function ui_layout(compile, lookup, appContext) {
}
}));
Runtime.setInterval((function () {
return grid.dataSource = Array.prototype.map.call(data, (function (param) {
var price = param[/* price */1];
var bid = price + 20 * Math.random();
var ask = price + 20 * Math.random();
var result = Curry._1(computeFunction[0], {
bid: bid,
ask: ask
});
return /* array */[
mk_titleRow(param[/* ticker */0]),
mk_titleRow(bid.toFixed(2)),
mk_titleRow(ask.toFixed(2)),
mk_titleRow(result.toFixed(2))
];
}));
grid.dataSource = Array.prototype.map.call(data, (function (param) {
var price = param[/* price */1];
var bid = price + 20 * Math.random();
var ask = price + 20 * Math.random();
var result = Curry._1(computeFunction[0], {
bid: bid,
ask: ask
});
return /* array */[
mk_titleRow(param[/* ticker */0]),
mk_titleRow(bid.toFixed(2)),
mk_titleRow(ask.toFixed(2)),
mk_titleRow(result.toFixed(2))
];
}));
return /* () */0;
}), 100);
return hw1;
}
Expand Down
10 changes: 10 additions & 0 deletions jscomp/test/gpr_2352_test.js
@@ -0,0 +1,10 @@
'use strict';


function f(x) {
x.hey = 22;
return /* () */0;
}

exports.f = f;
/* No side effect */
4 changes: 4 additions & 0 deletions jscomp/test/gpr_2352_test.ml
@@ -0,0 +1,4 @@


let f x =
x##hey#= 22
3 changes: 2 additions & 1 deletion jscomp/test/local_class_type.js
Expand Up @@ -3,7 +3,8 @@
var Caml_oo_curry = require("../../lib/js/caml_oo_curry.js");

function f(x) {
return x.height = 3;
x.height = 3;
return /* () */0;
}

function h(x) {
Expand Down
13 changes: 7 additions & 6 deletions jscomp/test/mutable_obj_test.js
Expand Up @@ -2,12 +2,13 @@


function f(x) {
return x.dec = (function (x) {
return {
x: x,
y: x
};
});
x.dec = (function (x) {
return {
x: x,
y: x
};
});
return /* () */0;
}

exports.f = f;
Expand Down
9 changes: 6 additions & 3 deletions jscomp/test/ppx_this_obj_field.js
Expand Up @@ -59,11 +59,13 @@ var v = {
y: 0,
reset: (function () {
var self = this ;
return self.y = 0;
self.y = 0;
return /* () */0;
}),
incr: (function () {
var self = this ;
return self.y = self.y + 1 | 0;
self.y = self.y + 1 | 0;
return /* () */0;
}),
getY: (function () {
var self = this ;
Expand Down Expand Up @@ -139,7 +141,8 @@ var zz = {
x: 3,
setX: (function (x) {
var self = this ;
return self.x = x;
self.x = x;
return /* () */0;
}),
getX: (function () {
var self = this ;
Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/test_case_set.js
Expand Up @@ -3,7 +3,8 @@
var Caml_oo_curry = require("../../lib/js/caml_oo_curry.js");

function f(x) {
return x.case = 3;
x.case = 3;
return /* () */0;
}

function g(x) {
Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/test_unsafe_obj_ffi.js
Expand Up @@ -12,7 +12,8 @@ function g(x) {

function h(x) {
x.height = 3;
return x.width = 3;
x.width = 3;
return /* () */0;
}

exports.f = f;
Expand Down
3 changes: 2 additions & 1 deletion jscomp/xwatcher/xwatcher_util.js
Expand Up @@ -72,7 +72,8 @@ function makeLock() {
}),
release: (function () {
var self = this ;
return self.isBuilding = /* false */0;
self.isBuilding = /* false */0;
return /* () */0;
})
};
}
Expand Down
36 changes: 17 additions & 19 deletions lib/whole_compiler.ml
Expand Up @@ -98201,37 +98201,35 @@ and
args = [obj]} as fn;
arg]
->
begin
let obj_block =
compile_lambda {cxt with st = NeedValue; should_return = ReturnFalse} obj
in
let value_block =
compile_lambda {cxt with st = NeedValue; should_return = ReturnFalse} arg
in
let cont block0 block1 obj_code =
begin
let need_value_no_return_cxt = {cxt with st = NeedValue; should_return = ReturnFalse} in
let obj_output = compile_lambda need_value_no_return_cxt obj in
let arg_output = compile_lambda need_value_no_return_cxt arg in
let cont obj_block arg_block obj_code =
Js_output.output_of_block_and_expression st should_return lam
(
match obj_code with
| None -> Ext_list.append block0 block1
| Some obj_code -> Ext_list.append block0 @@ obj_code :: block1
| None -> Ext_list.append obj_block arg_block
| Some obj_code -> Ext_list.append obj_block (obj_code :: arg_block)
)
in
match obj_block, value_block with
| {block = block0; value = Some obj },
{block = block1; value = Some value}
match obj_output, arg_output with
| {block = obj_block; value = Some obj },
{block = arg_block; value = Some value}
->
if Ext_string.ends_with method_name Literals.setter_suffix then
let property =
Lam_methname.translate ~loc @@
String.sub method_name 0
(String.length method_name - Literals.setter_suffix_len) in
Lam_methname.translate ~loc
(String.sub method_name 0
(String.length method_name - Literals.setter_suffix_len)) in
match Js_ast_util.named_expression obj with
| None ->
cont block0 block1 None (E.assign (E.dot obj property) value)
cont obj_block arg_block None
(E.seq (E.assign (E.dot obj property) value) E.unit)
| Some (obj_code, obj)
->
cont block0 block1 (Some obj_code)
(E.assign (E.dot (E.var obj) property) value)
cont obj_block arg_block (Some obj_code)
(E.seq (E.assign (E.dot (E.var obj) property) value) E.unit)
else
compile_lambda cxt
(Lam.apply fn [arg]
Expand Down

0 comments on commit 4d306ff

Please sign in to comment.