@@ -954,18 +954,19 @@ findLocation :: Env -> FilePath -> IO (Either Exit.BuildProjectProblem Location)
954954findLocation env path =
955955 do exists <- File.exists path
956956 if exists
957− then findLoc env path <$> Dir.canonicalizePath path
957+ then findLoc env path =<< Dir.canonicalizePath path
958958 else return (Left (Exit.BP_PathUnknown path))
959959
960960
961−findLoc :: Env -> FilePath -> FilePath -> Either Exit.BuildProjectProblem Location
961+findLoc :: Env -> FilePath -> FilePath -> IO (Either Exit.BuildProjectProblem Location)
962962findLoc (Env _ root _ srcDirs _ _) path absolutePath =
963963 let
964964 (dirs, file) = FP.splitFileName absolutePath
965965 (final, ext) = FP.splitExtension file
966966 in
967967 if ext /= ".elm"
968− then Left (Exit.BP_WithBadExtension path)
968+ then
969+ return $ Left $ Exit.BP_WithBadExtension path
969970 else
970971 let
971972 roots = FP.splitDirectories root
@@ -973,25 +974,47 @@ findLoc (Env _ root _ srcDirs _ _) path absolutePath =
973974 in
974975 case dropPrefix roots segments of
975976 Nothing ->
976− Right (Location absolutePath path (LOutside path))
977+ return $ Right $ Location absolutePath path (LOutside path)
977978
978979 Just relativeSegments ->
979− case Maybe.mapMaybe (isInsideSrcDir relativeSegments) srcDirs of
980− [] -> Right $ Location absolutePath path (LOutside path)
981− [(_, Right name)] -> Right $ Location absolutePath path (LInside name)
982− [(s, Left names)] -> Left $ Exit.BP_MainNameInvalid path s names
983− (s1,_):(s2,_):_ -> Left $ Exit.BP_WithAmbiguousSrcDir path s1 s2
980+ case Maybe.mapMaybe (isInsideSrcDirByPath relativeSegments) srcDirs of
981+ [] ->
982+ return $ Right $ Location absolutePath path (LOutside path)
984983
984+ [(_, Right names)] ->
985+ do let name = Name.fromChars (List.intercalate "." names)
986+ dirs <- filterM (isInsideSrcDirByName root names) srcDirs
987+ case dirs of
988+ d1:d2:_ ->
989+ do let p1 = d1 </> FP.joinPath names <.> "elm"
990+ let p2 = d2 </> FP.joinPath names <.> "elm"
991+ return $ Left $ Exit.BP_MainNameDuplicate name p1 p2
985992
986−isInsideSrcDir :: [String] -> FilePath -> Maybe (FilePath, Either [String] ModuleName.Raw)
987−isInsideSrcDir segments srcDir =
993+ _ ->
994+ return $ Right $ Location absolutePath path (LInside name)
995+
996+ [(s, Left names)] ->
997+ return $ Left $ Exit.BP_MainNameInvalid path s names
998+
999+ (s1,_):(s2,_):_ ->
1000+ return $ Left $ Exit.BP_WithAmbiguousSrcDir path s1 s2
1001+
1002+
1003+
1004+isInsideSrcDirByName :: FilePath -> [String] -> FilePath -> IO Bool
1005+isInsideSrcDirByName root names srcDir =
1006+ File.exists (root </> srcDir </> FP.joinPath names <.> "elm")
1007+
1008+
1009+isInsideSrcDirByPath :: [String] -> FilePath -> Maybe (FilePath, Either [String] [String])
1010+isInsideSrcDirByPath segments srcDir =
9881011 case dropPrefix (FP.splitDirectories srcDir) segments of
9891012 Nothing ->
9901013 Nothing
9911014
9921015 Just names ->
9931016 if all isGoodName names
994− then Just (srcDir, Right (Name.fromChars (List.intercalate "." names)))
1017+ then Just (srcDir, Right names)
9951018 else Just (srcDir, Left names)
9961019
9971020