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 wrong calls to Env.normalize_path on non-module paths #2131
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b6851de
Fix wrong use of normalize_path instead of normalize_path_prefix
alainfrisch acefa75
Non-regression test
alainfrisch 8118a72
Changelog
alainfrisch 27aaf4f
Reviewer comments
alainfrisch 703f195
Fix for inline record in extension constructor
alainfrisch 225817c
Bootstrap
alainfrisch File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
Binary file not shown.
Binary file not shown.
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,17 @@ | ||
(* TEST | ||
* expect | ||
*) | ||
|
||
module X = struct | ||
|
||
module B = List | ||
|
||
exception B of {x:int} | ||
end | ||
|
||
let _ = X.B {x=2} | ||
;; | ||
[%%expect{| | ||
module X : sig module B = List exception B of { x : int; } end | ||
- : exn = X.B {x = 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
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 |
---|---|---|
|
@@ -1106,18 +1106,25 @@ let add_required_global id = | |
&& not (List.exists (Ident.same id) !required_globals) | ||
then required_globals := id :: !required_globals | ||
|
||
let rec normalize_path lax env path = | ||
let path = | ||
match path with | ||
Pdot(p, s) -> | ||
Pdot(normalize_path lax env p, s) | ||
| Papply(p1, p2) -> | ||
Papply(normalize_path lax env p1, normalize_path true env p2) | ||
| _ -> path | ||
in | ||
let rec normalize_module_path lax env = function | ||
| Pident id as path when lax && Ident.persistent id -> | ||
path (* fast path (avoids lookup) *) | ||
| Pdot (p, s) as path -> | ||
let p' = normalize_module_path lax env p in | ||
if p == p' then expand_module_path lax env path | ||
else expand_module_path lax env (Pdot(p', s)) | ||
| Papply (p1, p2) as path -> | ||
let p1' = normalize_module_path lax env p1 in | ||
let p2' = normalize_module_path true env p2 in | ||
if p1 == p1' && p2 == p2' then expand_module_path lax env path | ||
else expand_module_path lax env (Papply(p1', p2')) | ||
| Pident _ as path -> | ||
expand_module_path lax env path | ||
|
||
and expand_module_path lax env path = | ||
try match find_module ~alias:true path env with | ||
{md_type=Mty_alias path1} -> | ||
let path' = normalize_path lax env path1 in | ||
let path' = normalize_module_path lax env path1 in | ||
if lax || !Clflags.transparent_modules then path' else | ||
let id = Path.head path in | ||
if Ident.global id && not (Ident.same id (Path.head path')) | ||
|
@@ -1128,22 +1135,50 @@ let rec normalize_path lax env path = | |
|| (match path with Pident id -> not (Ident.persistent id) | _ -> true) -> | ||
path | ||
|
||
let normalize_path oloc env path = | ||
try normalize_path (oloc = None) env path | ||
let normalize_module_path oloc env path = | ||
try normalize_module_path (oloc = None) env path | ||
with Not_found -> | ||
match oloc with None -> assert false | ||
| Some loc -> | ||
raise (Error(Missing_module(loc, path, normalize_path true env path))) | ||
raise (Error(Missing_module(loc, path, | ||
normalize_module_path true env path))) | ||
|
||
let normalize_path_prefix oloc env path = | ||
match path with | ||
Pdot(p, s) -> | ||
Pdot(normalize_path oloc env p, s) | ||
let p2 = normalize_module_path oloc env p in | ||
if p == p2 then path else Pdot(p2, s) | ||
| Pident _ -> | ||
path | ||
| Papply _ -> | ||
assert false | ||
|
||
let is_uident s = | ||
match s.[0] with | ||
| 'A'..'Z' -> true | ||
| _ -> false | ||
|
||
let normalize_type_path oloc env path = | ||
(* Inlined version of Path.is_constructor_typath: | ||
constructor type paths (i.e. path pointing to an inline | ||
record argument of a constructpr) are built as a regular | ||
type path followed by a capitalized constructor name. *) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about |
||
match path with | ||
| Pident _ -> | ||
path | ||
| Pdot(p, s) -> | ||
let p2 = | ||
if is_uident s && not (is_uident (Path.last p)) then | ||
(* Cstr M.t.C *) | ||
normalize_path_prefix oloc env p | ||
else | ||
(* Regular M.t, Ext M.C *) | ||
normalize_module_path oloc env p | ||
in | ||
if p == p2 then path else Pdot (p2, s) | ||
| Papply _ -> | ||
assert false | ||
|
||
let find_module path env = | ||
find_module ~alias:false path env | ||
|
||
|
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
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
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.
What about calling this function
expand_module_path
rathernormalize_module_path0
?