diff --git a/src/bin/expect_tests/get_scope.ml b/src/bin/expect_tests/get_scope.ml index 25c9ca893..d4764bf85 100644 --- a/src/bin/expect_tests/get_scope.ml +++ b/src/bin/expect_tests/get_scope.ml @@ -6,117 +6,121 @@ let%expect_test _ = run_ligo_good [ "get-scope" ; gs "lambda_letin.mligo" ; "--format=dev" ] ; [%expect {| Scopes: - [ f5 a0 ] in file "lambda_letin.mligo", line 9, characters 2-7 - [ k4 j2 i1 g3 a0 ] in file "lambda_letin.mligo", line 7, characters 4-21 - [ j2 i1 g3 a0 ] in file "lambda_letin.mligo", line 6, character 4 to line 7, character 21 - [ j2 i1 a0 ] in file "lambda_letin.mligo", line 5, character 4 to line 7, character 21 + [ f#5 a#0 ] in file "lambda_letin.mligo", line 9, characters 2-7 + [ k#4 j#2 i#1 g#3 a#0 ] in file "lambda_letin.mligo", line 7, characters 4-21 + [ j#2 i#1 g#3 a#0 ] in file "lambda_letin.mligo", line 6, character 4 to line 7, character 21 + [ j#2 i#1 a#0 ] in file "lambda_letin.mligo", line 5, character 4 to line 7, character 21 [ ] in file "lambda_letin.mligo", line 1, characters 0-9 Variable definitions: - (k4 -> k) in file "lambda_letin.mligo", line 6, characters 12-25 - (j2 -> j) in file "lambda_letin.mligo", line 5, character 4 to line 7, character 21 - (i1 -> i) in file "lambda_letin.mligo", line 4, character 32 to line 7, character 21 - (g3 -> g) in file "lambda_letin.mligo", line 5, characters 12-21 - (f5 -> f) in file "lambda_letin.mligo", line 4, characters 8-9 - (b6 -> b) in file "lambda_letin.mligo", line 3, character 0 to line 9, character 7 - (a0 -> a) in file "lambda_letin.mligo", line 1, characters 0-9 + (k#4 -> k) in file "lambda_letin.mligo", line 6, characters 12-25 + (j#2 -> j) in file "lambda_letin.mligo", line 5, character 4 to line 7, character 21 + (i#1 -> i) in file "lambda_letin.mligo", line 4, character 32 to line 7, character 21 + (g#3 -> g) in file "lambda_letin.mligo", line 5, characters 12-21 + (f#5 -> f) in file "lambda_letin.mligo", line 4, characters 8-9 + (b#6 -> b) in file "lambda_letin.mligo", line 3, character 0 to line 9, character 7 + (a#0 -> a) in file "lambda_letin.mligo", line 1, characters 0-9 Type definitions: |} ]; run_ligo_good [ "get-scope" ; gs "letin.mligo" ; "--format=dev" ] ; [%expect {| Scopes: - [ d4 c1 a0 ] in file "letin.mligo", line 10, characters 2-11 - [ f3 e2 c1 a0 ] in file "letin.mligo", line 8, characters 4-17 - [ e2 c1 a0 ] in file "letin.mligo", line 7, character 4 to line 8, character 17 - [ c1 a0 ] in file "letin.mligo", line 6, character 4 to line 8, character 17 - [ a0 ] in file "letin.mligo", line 4, character 2 to line 10, character 11 + [ d#4 c#1 a#0 ] in file "letin.mligo", line 10, characters 2-11 + [ f#3 e#2 c#1 a#0 ] in file "letin.mligo", line 8, characters 4-17 + [ e#2 c#1 a#0 ] in file "letin.mligo", line 7, character 4 to line 8, character 17 + [ c#1 a#0 ] in file "letin.mligo", line 6, character 4 to line 8, character 17 + [ a#0 ] in file "letin.mligo", line 4, character 2 to line 10, character 11 [ ] in file "letin.mligo", line 1, characters 0-9 Variable definitions: - (f3 -> f) in file "letin.mligo", line 7, characters 12-21 - (e2 -> e) in file "letin.mligo", line 6, characters 12-17 - (d4 -> d) in file "letin.mligo", line 6, character 4 to line 8, character 17 - (c1 -> c) in file "letin.mligo", line 4, characters 10-15 - (b5 -> b) in file "letin.mligo", line 3, character 0 to line 10, character 11 - (a0 -> a) in file "letin.mligo", line 1, characters 0-9 + (f#3 -> f) in file "letin.mligo", line 7, characters 12-21 + (e#2 -> e) in file "letin.mligo", line 6, characters 12-17 + (d#4 -> d) in file "letin.mligo", line 6, character 4 to line 8, character 17 + (c#1 -> c) in file "letin.mligo", line 4, characters 10-15 + (b#5 -> b) in file "letin.mligo", line 3, character 0 to line 10, character 11 + (a#0 -> a) in file "letin.mligo", line 1, characters 0-9 Type definitions: |} ] ; run_ligo_good [ "get-scope" ; gs "lambda.mligo" ; "--format=dev" ] ; [%expect {| Scopes: - [ f3 a0 ] in file "lambda.mligo", line 5, characters 2-7 - [ j2 i1 a0 ] in file "lambda.mligo", line 4, characters 58-63 + [ f#3 a#0 ] in file "lambda.mligo", line 5, characters 2-7 + [ j#2 i#1 a#0 ] in file "lambda.mligo", line 4, characters 58-63 [ ] in file "lambda.mligo", line 1, characters 0-9 Variable definitions: - (j2 -> j) in file "lambda.mligo", line 4, characters 58-63 - (i1 -> i) in file "lambda.mligo", line 4, characters 31-63 - (f3 -> f) in file "lambda.mligo", line 4, characters 8-9 - (b4 -> b) in file "lambda.mligo", line 3, character 0 to line 5, character 7 - (a0 -> a) in file "lambda.mligo", line 1, characters 0-9 + (j#2 -> j) in file "lambda.mligo", line 4, characters 58-63 + (i#1 -> i) in file "lambda.mligo", line 4, characters 31-63 + (f#3 -> f) in file "lambda.mligo", line 4, characters 8-9 + (b#4 -> b) in file "lambda.mligo", line 3, character 0 to line 5, character 7 + (a#0 -> a) in file "lambda.mligo", line 1, characters 0-9 Type definitions: |} ] ; run_ligo_good [ "get-scope" ; gs "match.mligo" ; "--format=dev" ] ; [%expect {| Scopes: - [ s11 mytype0 c9 b5 a1 ] in file "match.mligo", line 19, characters 16-21 - [ mytype0 c9 b5 a1 ] in file "match.mligo", line 20, characters 12-13 - [ mytype0 d10 c9 b5 a1 ] in file "match.mligo", line 18, characters 22-32 - [ mytype0 c9 b5 a1 ] in file "match.mligo", line 18, characters 9-32 - [ tl8 mytype0 hd7 b5 a1 ] in file "match.mligo", line 15, characters 14-15 - [ mytype0 c6 b5 a1 ] in file "match.mligo", line 14, characters 4-5 - [ mytype0 b5 a1 ] in file "match.mligo", line 13, character 4 to line 14, character 5 - [ mytype0 b5 a1 ] in file "match.mligo", line 11, characters 9-21 - [ y4 mytype0 a1 ] in file "match.mligo", line 8, characters 13-18 - [ x3 mytype0 a1 ] in file "match.mligo", line 7, characters 13-18 - [ mytype0 c2 a1 ] in file "match.mligo", line 6, characters 22-27 - [ mytype0 a1 ] in file "match.mligo", line 6, characters 9-27 - [ mytype0 ] in file "match.mligo", line 3, characters 0-9 + [ s#11 mytype#0 c#9 b#5 a#1 ] in file "match.mligo", line 19, characters 16-21 + [ mytype#0 c#9 b#5 a#1 ] in file "match.mligo", line 20, characters 12-13 + [ mytype#0 d#10 c#9 b#5 a#1 ] in file "match.mligo", line 18, characters 22-32 + [ mytype#0 c#9 b#5 a#1 ] in file "match.mligo", line 18, characters 9-32 + [ tl#8 mytype#0 hd#7 b#5 a#1 ] in file "match.mligo", line 15, characters 14-15 + [ mytype#0 c#6 b#5 a#1 ] in file "match.mligo", line 14, characters 4-5 + [ mytype#0 b#5 a#1 ] in file "match.mligo", line 13, character 4 to line 14, character 5 + [ mytype#0 b#5 a#1 ] in file "match.mligo", line 11, characters 9-21 + [ y#4 mytype#0 a#1 ] in file "match.mligo", line 8, characters 13-18 + [ x#3 mytype#0 a#1 ] in file "match.mligo", line 7, characters 13-18 + [ mytype#0 c#2 a#1 ] in file "match.mligo", line 6, characters 22-27 + [ mytype#0 a#1 ] in file "match.mligo", line 6, characters 9-27 + [ mytype#0 ] in file "match.mligo", line 3, characters 0-9 Variable definitions: - (s11 -> s) in file "match.mligo", line 19, characters 16-21 - (d12 -> d) in file "match.mligo", line 17, character 0 to line 20, character 3 - (d10 -> d) in file "match.mligo", line 18, characters 17-18 - (c9 -> c) in file "match.mligo", line 10, character 0 to line 15, character 3 - (b5 -> b) in file "match.mligo", line 5, character 0 to line 8, character 3 - (a1 -> a) in file "match.mligo", line 3, characters 0-9 + (s#11 -> s) in file "match.mligo", line 19, characters 16-21 + (d#12 -> d) in file "match.mligo", line 17, character 0 to line 20, character 3 + (d#10 -> d) in file "match.mligo", line 18, characters 17-18 + (c#9 -> c) in file "match.mligo", line 10, character 0 to line 15, character 3 + (b#5 -> b) in file "match.mligo", line 5, character 0 to line 8, character 3 + (a#1 -> a) in file "match.mligo", line 3, characters 0-9 Type definitions: - (mytype0 -> mytype) in file "match.mligo", line 1, characters 0-40 |} ] ; + (mytype#0 -> mytype) in file "match.mligo", line 1, characters 0-40 |} ] ; run_ligo_good [ "get-scope" ; gs "rec.mligo" ; "--format=dev" ] ; [%expect {| Scopes: - [ k4 j3 i2 c1 a0 ] in file "rec.mligo", line 6, characters 4-11 - [ j3 i2 c1 a0 ] in file "rec.mligo", line 5, character 4 to line 6, character 11 - [ i2 c1 a0 ] in file "rec.mligo", line 4, characters 36-49 - [ c1 a0 ] in file "rec.mligo", line 4, characters 36-49 - [ c1 a0 ] + [ c#5 b#6 a#0 ] in file "rec.mligo", line 9, characters 2-10 + [ c#5 a#0 ] in file "rec.mligo", line 8, character 2 to line 9, character 10 + [ k#4 j#3 i#2 c#1 a#0 ] in file "rec.mligo", line 6, characters 4-11 + [ j#3 i#2 c#1 a#0 ] in file "rec.mligo", line 5, character 4 to line 6, character 11 + [ i#2 c#1 a#0 ] in file "rec.mligo", line 4, characters 36-49 + [ c#1 a#0 ] in file "rec.mligo", line 4, characters 36-49 + [ c#1 a#0 ] [ ] in file "rec.mligo", line 1, characters 0-9 Variable definitions: - (k4 -> k) in file "rec.mligo", line 5, characters 12-21 - (j3 -> j) - (i2 -> i) - (c1 -> c) in file "rec.mligo", line 4, character 2 to line 8, character 9 - (b5 -> b) in file "rec.mligo", line 3, character 0 to line 8, character 9 - (a0 -> a) in file "rec.mligo", line 1, characters 0-9 + (k#4 -> k) in file "rec.mligo", line 5, characters 12-21 + (j#3 -> j) + (i#2 -> i) + (c#5 -> c) in file "rec.mligo", line 4, characters 12-13 + (c#1 -> c) in file "rec.mligo", line 4, characters 12-13 + (b#7 -> b) in file "rec.mligo", line 3, character 0 to line 9, character 10 + (b#6 -> b) in file "rec.mligo", line 8, characters 10-11 + (a#0 -> a) in file "rec.mligo", line 1, characters 0-9 Type definitions: |} ] ; run_ligo_good [ "get-scope" ; gs "shadowing.mligo" ; "--format=dev" ] ; [%expect {| Scopes: - [ d4 c1 a0 ] in file "shadowing.mligo", line 10, characters 2-11 - [ e2 c1 a3 ] in file "shadowing.mligo", line 8, characters 4-13 - [ e2 c1 a0 ] in file "shadowing.mligo", line 7, character 4 to line 8, character 13 - [ c1 a0 ] in file "shadowing.mligo", line 6, character 4 to line 8, character 13 - [ a0 ] in file "shadowing.mligo", line 4, character 2 to line 10, character 11 + [ d#4 c#1 a#0 ] in file "shadowing.mligo", line 10, characters 2-11 + [ e#2 c#1 a#3 ] in file "shadowing.mligo", line 8, characters 4-13 + [ e#2 c#1 a#0 ] in file "shadowing.mligo", line 7, character 4 to line 8, character 13 + [ c#1 a#0 ] in file "shadowing.mligo", line 6, character 4 to line 8, character 13 + [ a#0 ] in file "shadowing.mligo", line 4, character 2 to line 10, character 11 [ ] in file "shadowing.mligo", line 1, characters 0-9 Variable definitions: - (e2 -> e) in file "shadowing.mligo", line 6, characters 12-17 - (d4 -> d) in file "shadowing.mligo", line 6, character 4 to line 8, character 13 - (c1 -> c) in file "shadowing.mligo", line 4, characters 10-15 - (b5 -> b) in file "shadowing.mligo", line 3, character 0 to line 10, character 11 - (a3 -> a) in file "shadowing.mligo", line 7, characters 12-21 - (a0 -> a) in file "shadowing.mligo", line 1, characters 0-9 + (e#2 -> e) in file "shadowing.mligo", line 6, characters 12-17 + (d#4 -> d) in file "shadowing.mligo", line 6, character 4 to line 8, character 13 + (c#1 -> c) in file "shadowing.mligo", line 4, characters 10-15 + (b#5 -> b) in file "shadowing.mligo", line 3, character 0 to line 10, character 11 + (a#3 -> a) in file "shadowing.mligo", line 7, characters 12-21 + (a#0 -> a) in file "shadowing.mligo", line 1, characters 0-9 Type definitions: |} ] ; \ No newline at end of file diff --git a/src/main/scopes/scopes.ml b/src/main/scopes/scopes.ml index cc9d73e00..1c2c36f45 100644 --- a/src/main/scopes/scopes.ml +++ b/src/main/scopes/scopes.ml @@ -12,22 +12,19 @@ let scopes : with_types:bool -> string -> string -> ((def_map * scopes), Main_er let rec find_scopes' = fun (i,all_defs,env,scopes,lastloc) (e : Ast_core.expression) -> match e.content with | E_let_in { let_binder = (fn,_) ; rhs ; let_result } -> ( - match rhs.content with - | E_recursive { fun_name ; fun_type ; lambda = { result;_ } } -> ( - (* Note: - It is not entirely true that 'fun_name' is in 'result' scope; because only tail calls are allowed - *) - let def = make_v_def_option_type fun_name (Some fun_type) e.location e.location in - let (i,env) = add_shadowing_def (i,fun_name) def env in - find_scopes' (i,all_defs,env,scopes,result.location) result - ) - | _ -> ( - (*TODO : n needs location and should be used bellow in union with rhs *) - let (i,all_defs,_, scopes) = find_scopes' (i,all_defs,env,scopes,e.location) rhs in - let (i,env) = add_shadowing_def (i,fn) (make_v_def_from_core fn rhs rhs.location rhs.location) env in - let all_defs = merge_defs env all_defs in - find_scopes' (i,all_defs,env,scopes,let_result.location) let_result - ) + (*TODO : n needs location and should be used bellow in union with rhs *) + let (i,all_defs,_, scopes) = find_scopes' (i,all_defs,env,scopes,e.location) rhs in + let (i,env) = add_shadowing_def (i,fn) (make_v_def_from_core fn rhs rhs.location rhs.location) env in + let all_defs = merge_defs env all_defs in + find_scopes' (i,all_defs,env,scopes,let_result.location) let_result + ) + | E_recursive { fun_name ; fun_type ; lambda = { result;_ } } -> ( + (* Note: + It is not entirely true that 'fun_name' is in 'result' scope; because only tail calls are allowed + *) + let def = make_v_def_option_type fun_name (Some fun_type) e.location e.location in + let (i,env) = add_shadowing_def (i,fun_name) def env in + find_scopes' (i,all_defs,env,scopes,result.location) result ) | E_lambda { binder ; input_type ; output_type = _ ; result } -> ( let (i,env) = add_shadowing_def (i,binder) (make_v_def_option_type binder input_type result.location result.location) env in diff --git a/src/test/contracts/get_scope_tests/rec.mligo b/src/test/contracts/get_scope_tests/rec.mligo index 4d95f0a55..6e2423ae5 100644 --- a/src/test/contracts/get_scope_tests/rec.mligo +++ b/src/test/contracts/get_scope_tests/rec.mligo @@ -5,4 +5,5 @@ let b = let k = i + j + a in c (k,1) in - c (a,2) \ No newline at end of file + let b = 2 in + c (a, b)