@@ -2868,21 +2868,24 @@ algorithm
28682868 if AbsynUtil . pathIsFullyQualified(qualified_path) then
28692869 qualified_path := AbsynUtil . makeNotFullyQualified(qualified_path);
28702870
2871- if AbsynUtil . pathIsQual(qualified_path) then
2872- // If the path is qualified it needs to be joined with the original path,
2873- // but we remove any part of the path that's the same as the destination.
2871+ if AbsynUtil . pathIsIdent(qualified_path) and
2872+ AbsynUtil . pathFirstIdent(qualified_path) == AbsynUtil . pathFirstIdent(env. destinationPath) then
2873+ // Special case, the path refers to the destination package, e.g. moving A.B.C into A.
2874+ path := AbsynUtil . pathRest(path);
2875+ else
2876+ // Remove any part of the qualified path that's the same as the destination.
28742877 opt_path := AbsynUtil . pathStripSamePrefix(qualified_path, env. destinationPath);
28752878
2879+ // Replace the first identifier in the original path with the remaining qualified path.
28762880 if isSome(opt_path) then
28772881 SOME (qualified_path) := opt_path;
28782882
2879- if AbsynUtil . pathIsQual(qualified_path) then
2880- path := AbsynUtil . joinPaths(AbsynUtil . pathPrefix(qualified_path), path);
2883+ if AbsynUtil . pathIsQual(path) then
2884+ path := AbsynUtil . joinPaths(qualified_path, AbsynUtil . pathRest(path));
2885+ else
2886+ path := qualified_path;
28812887 end if ;
28822888 end if ;
2883- elseif AbsynUtil . pathFirstIdent(qualified_path) == AbsynUtil . pathFirstIdent(env. destinationPath) then
2884- // Special case, the path refers to the destination package, e.g. moving path A.B.C into A.
2885- path := AbsynUtil . pathRest(path);
28862889 end if ;
28872890 end if ;
28882891end updateMovedPath;
@@ -2967,6 +2970,7 @@ function updateMovedCref
29672970 input MoveEnv env;
29682971protected
29692972 Absyn . Path qualified_path;
2973+ Absyn . ComponentRef qualified_cref;
29702974 Option < Absyn . Path > opt_path;
29712975algorithm
29722976 if AbsynUtil . crefIsFullyQualified(cref) or AbsynUtil . crefIsWild(cref) then
@@ -2987,21 +2991,25 @@ algorithm
29872991 if AbsynUtil . pathIsFullyQualified(qualified_path) then
29882992 qualified_path := AbsynUtil . makeNotFullyQualified(qualified_path);
29892993
2990- if AbsynUtil . pathIsQual(qualified_path) then
2991- // If the path is qualified it needs to be joined with the original cref,
2992- // but we remove any part of the path that's the same as the destination.
2994+ if AbsynUtil . pathIsIdent(qualified_path) and
2995+ AbsynUtil . pathFirstIdent(qualified_path) == AbsynUtil . pathFirstIdent(env. destinationPath) then
2996+ // Special case, the cref refers to the destination package, e.g. moving A.B.C into A.
2997+ cref := AbsynUtil . crefStripFirst(cref);
2998+ else
2999+ // Remove any part of the qualified path that's the same as the destination.
29933000 opt_path := AbsynUtil . pathStripSamePrefix(qualified_path, env. destinationPath);
29943001
3002+ // Replace the first identifier in the original cref with the remaining qualified path.
29953003 if isSome(opt_path) then
29963004 SOME (qualified_path) := opt_path;
3005+ qualified_cref := AbsynUtil . pathToCref(qualified_path);
29973006
2998- if AbsynUtil . pathIsQual(qualified_path) then
2999- cref := AbsynUtil . joinCrefs(AbsynUtil . pathToCref(AbsynUtil . pathPrefix(qualified_path)), cref);
3007+ if AbsynUtil . crefIsQual(cref) then
3008+ cref := AbsynUtil . joinCrefs(qualified_cref, AbsynUtil . crefStripFirst(cref));
3009+ else
3010+ cref := qualified_cref;
30003011 end if ;
30013012 end if ;
3002- elseif AbsynUtil . pathFirstIdent(qualified_path) == AbsynUtil . pathFirstIdent(env. destinationPath) then
3003- // Special case, the cref refers to the destination package, e.g. moving path A.B.C into A.
3004- cref := AbsynUtil . crefStripFirst(cref);
30053013 end if ;
30063014 end if ;
30073015end updateMovedCref;
0 commit comments