diff --git a/Cabal/Cabal.cabal b/Cabal/Cabal.cabal index 7bdfac8a14d..1d0a59b8537 100644 --- a/Cabal/Cabal.cabal +++ b/Cabal/Cabal.cabal @@ -161,6 +161,9 @@ extra-source-files: tests/ParserTests/regressions/issue-5055.cabal tests/ParserTests/regressions/issue-5055.expr tests/ParserTests/regressions/issue-5055.format + tests/ParserTests/regressions/issue-5846.cabal + tests/ParserTests/regressions/issue-5846.expr + tests/ParserTests/regressions/issue-5846.format tests/ParserTests/regressions/issue-774.cabal tests/ParserTests/regressions/issue-774.check tests/ParserTests/regressions/issue-774.expr diff --git a/Cabal/Distribution/Types/Dependency.hs b/Cabal/Distribution/Types/Dependency.hs index f467b03fac1..65ae4660aba 100644 --- a/Cabal/Distribution/Types/Dependency.hs +++ b/Cabal/Distribution/Types/Dependency.hs @@ -88,12 +88,17 @@ instance Parsec Dependency where $ (char ':' *> spaces *>) $ versionGuardMultilibs $ pure <$> parseLib name <|> parseMultipleLibs name + + spaces -- https://github.com/haskell/cabal/issues/5846 + ver <- parsec <|> pure anyVersion return $ Dependency name ver $ Set.fromList libs - where makeLib pn ln | unPackageName pn == ln = LMainLibName - | otherwise = LSubLibName $ mkUnqualComponentName ln - parseLib pn = makeLib pn <$> parsecUnqualComponentName - parseMultipleLibs pn = between (char '{' *> spaces) + where + makeLib pn ln + | unPackageName pn == ln = LMainLibName + | otherwise = LSubLibName $ mkUnqualComponentName ln + parseLib pn = makeLib pn <$> parsecUnqualComponentName + parseMultipleLibs pn = between (char '{' *> spaces) (spaces <* char '}') $ parsecCommaList $ parseLib pn diff --git a/Cabal/tests/ParserTests.hs b/Cabal/tests/ParserTests.hs index e93108137d7..fd7daf70f69 100644 --- a/Cabal/tests/ParserTests.hs +++ b/Cabal/tests/ParserTests.hs @@ -178,6 +178,7 @@ regressionTests = testGroup "regressions" , regressionTest "mixin-3.cabal" , regressionTest "libpq1.cabal" , regressionTest "libpq2.cabal" + , regressionTest "issue-5846.cabal" , regressionTest "indentation.cabal" , regressionTest "indentation2.cabal" , regressionTest "indentation3.cabal" diff --git a/Cabal/tests/ParserTests/regressions/issue-5846.cabal b/Cabal/tests/ParserTests/regressions/issue-5846.cabal new file mode 100644 index 00000000000..dc76d4059d2 --- /dev/null +++ b/Cabal/tests/ParserTests/regressions/issue-5846.cabal @@ -0,0 +1,11 @@ +cabal-version: 3.0 +name: issue +version: 5846 + +library + default-language: Haskell2010 + build-depends: lib1:{a,b} + , lib2:c + + build-depends: lib3:d>=1 + build-depends: lib4:{a,b}>=1 diff --git a/Cabal/tests/ParserTests/regressions/issue-5846.expr b/Cabal/tests/ParserTests/regressions/issue-5846.expr new file mode 100644 index 00000000000..6b2b7f707ea --- /dev/null +++ b/Cabal/tests/ParserTests/regressions/issue-5846.expr @@ -0,0 +1,145 @@ +GenericPackageDescription + {condBenchmarks = [], + condExecutables = [], + condForeignLibs = [], + condLibrary = Just + CondNode + {condTreeComponents = [], + condTreeConstraints = [Dependency + `PackageName "lib1"` + AnyVersion + (Set.fromList + [LSubLibName `UnqualComponentName "a"`, + LSubLibName `UnqualComponentName "b"`]), + Dependency + `PackageName "lib2"` + AnyVersion + (Set.fromList + [LSubLibName `UnqualComponentName "c"`]), + Dependency + `PackageName "lib3"` + (OrLaterVersion `mkVersion [1]`) + (Set.fromList + [LSubLibName `UnqualComponentName "d"`]), + Dependency + `PackageName "lib4"` + (OrLaterVersion `mkVersion [1]`) + (Set.fromList + [LSubLibName `UnqualComponentName "a"`, + LSubLibName `UnqualComponentName "b"`])], + condTreeData = Library + {exposedModules = [], + libBuildInfo = BuildInfo + {asmOptions = [], + asmSources = [], + autogenIncludes = [], + autogenModules = [], + buildToolDepends = [], + buildTools = [], + buildable = True, + cSources = [], + ccOptions = [], + cmmOptions = [], + cmmSources = [], + cppOptions = [], + customFieldsBI = [], + cxxOptions = [], + cxxSources = [], + defaultExtensions = [], + defaultLanguage = Just Haskell2010, + extraBundledLibs = [], + extraDynLibFlavours = [], + extraFrameworkDirs = [], + extraGHCiLibs = [], + extraLibDirs = [], + extraLibFlavours = [], + extraLibs = [], + frameworks = [], + hsSourceDirs = [], + includeDirs = [], + includes = [], + installIncludes = [], + jsSources = [], + ldOptions = [], + mixins = [], + oldExtensions = [], + options = PerCompilerFlavor [] [], + otherExtensions = [], + otherLanguages = [], + otherModules = [], + pkgconfigDepends = [], + profOptions = PerCompilerFlavor [] [], + sharedOptions = PerCompilerFlavor [] [], + staticOptions = PerCompilerFlavor [] [], + targetBuildDepends = [Dependency + `PackageName "lib1"` + AnyVersion + (Set.fromList + [LSubLibName + `UnqualComponentName "a"`, + LSubLibName + `UnqualComponentName "b"`]), + Dependency + `PackageName "lib2"` + AnyVersion + (Set.fromList + [LSubLibName + `UnqualComponentName "c"`]), + Dependency + `PackageName "lib3"` + (OrLaterVersion + `mkVersion [1]`) + (Set.fromList + [LSubLibName + `UnqualComponentName "d"`]), + Dependency + `PackageName "lib4"` + (OrLaterVersion + `mkVersion [1]`) + (Set.fromList + [LSubLibName + `UnqualComponentName "a"`, + LSubLibName + `UnqualComponentName "b"`])], + virtualModules = []}, + libExposed = True, + libName = LMainLibName, + libVisibility = LibraryVisibilityPublic, + reexportedModules = [], + signatures = []}}, + condSubLibraries = [], + condTestSuites = [], + genPackageFlags = [], + packageDescription = PackageDescription + {author = "", + benchmarks = [], + bugReports = "", + buildTypeRaw = Nothing, + category = "", + copyright = "", + customFieldsPD = [], + dataDir = "", + dataFiles = [], + description = "", + executables = [], + extraDocFiles = [], + extraSrcFiles = [], + extraTmpFiles = [], + foreignLibs = [], + homepage = "", + library = Nothing, + licenseFiles = [], + licenseRaw = Left NONE, + maintainer = "", + package = PackageIdentifier + {pkgName = `PackageName "issue"`, + pkgVersion = `mkVersion [5846]`}, + pkgUrl = "", + setupBuildInfo = Nothing, + sourceRepos = [], + specVersionRaw = Left `mkVersion [3,0]`, + stability = "", + subLibraries = [], + synopsis = "", + testSuites = [], + testedWith = []}} diff --git a/Cabal/tests/ParserTests/regressions/issue-5846.format b/Cabal/tests/ParserTests/regressions/issue-5846.format new file mode 100644 index 00000000000..7ddb6afaee1 --- /dev/null +++ b/Cabal/tests/ParserTests/regressions/issue-5846.format @@ -0,0 +1,11 @@ +cabal-version: 3.0 +name: issue +version: 5846 + +library + default-language: Haskell2010 + build-depends: + lib1 : {a, b} -any, + lib2 : {c} -any, + lib3 : {d} >=1, + lib4 : {a, b} >=1