Skip to content


fixed crash when printing latest versions with 'cabal install' #1018

merged 1 commit into from

2 participants


A recent patch introduced the feature that 'cabal install --dry-run' would print latest version numbers for packages to be installed. This failed if the package that was installed (the actual target, not a dep) wasn't uploaded to hackage:

cabal: Prelude.last: empty list

This patch fixes this.

(This is my first patch to cabal. If I did violate some coding or other guidelines, please tell me!)


Is lookupPackageName really guaranteed to return packages in version order?

Hmm... aha, I see that it is, according to, but this really ought to be better documented...

The last was introduced in the previous patch. I don't know about lookupPackageName.


Right, I know last was from the previous patch, I just hadn't looked at the previous patch carefully so commented here. In any case, all is well.


Also, when I said "this ought to be better documented", I meant in Distribution.Client.PackageIndex, not here.

I see. Indeed, all is well. Thanks for merging.

@byorgey byorgey merged commit 47f280e into haskell:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 7 deletions.
  1. +12 −7 cabal-install/Distribution/Client/Install.hs
19 cabal-install/Distribution/Client/Install.hs
@@ -506,15 +506,20 @@ printPlan dryRun verbosity plan sourcePkgDb = case plan of
diff -> " changes: " ++ intercalate ", " (map change diff)
showLatest :: ConfiguredPackage -> String
- showLatest pkg = if pkgVersion /= latestVersion
- then (" (latest: " ++ display latestVersion ++ ")")
- else ""
+ showLatest pkg = case mLatestVersion of
+ Just latestVersion ->
+ if pkgVersion /= latestVersion
+ then (" (latest: " ++ display latestVersion ++ ")")
+ else ""
+ Nothing -> ""
pkgVersion = packageVersion pkg
- latestVersion =
- packageVersion . last
- . SourcePackageIndex.lookupPackageName (packageIndex sourcePkgDb)
- $ (packageName pkg)
+ mLatestVersion :: Maybe Version
+ mLatestVersion = case SourcePackageIndex.lookupPackageName
+ (packageIndex sourcePkgDb)
+ (packageName pkg) of
+ [] -> Nothing
+ x -> Just $ packageVersion $ last x
toFlagAssignment :: [Flag] -> FlagAssignment
toFlagAssignment = map (\ f -> (flagName f, flagDefault f))
Something went wrong with that request. Please try again.