Skip to content
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

Warn when fixities are different from base #1069

Closed
wants to merge 5 commits into from

Conversation

brandonchinn178
Copy link
Collaborator

Resolves #1060

Tested with:

{-# LANGUAGE NoImplicitPrelude #-}

import MyCustomPrelude

main :: IO ()
main =
  putStrLn $
    "hello " ++ "world"

This shows the following with --debug:

*** WARNING *** Operator is possibly using the wrong fixity. Got: FixityApproximation {faDirection = Just InfixL, faMinPrecedence = 9, faMaxPrecedence = 9}, Fixities being shadowed: [FixityInfo {fiDirection = InfixR, fiPrecedence = 5},FixityInfo {fiDirection = InfixR, fiPrecedence = 5},FixityInfo {fiDirection = InfixR, fiPrecedence = 5},FixityInfo {fiDirection = InfixR, fiPrecedence = 5},FixityInfo {fiDirection = InfixR, fiPrecedence = 5}]
*** WARNING *** Operator is possibly using the wrong fixity. Got: FixityApproximation {faDirection = Just InfixL, faMinPrecedence = 9, faMaxPrecedence = 9}, Fixities being shadowed: [FixityInfo {fiDirection = InfixR, fiPrecedence = 0},FixityInfo {fiDirection = InfixR, fiPrecedence = 0},FixityInfo {fiDirection = InfixR, fiPrecedence = 0}]

Comment on lines +92 to +97
relativeCabalFile <- makeRelativeToCurrentDirectory (ciCabalFilePath cabalInfo)
logDebugM "CABAL FILE" $
"Found .cabal file "
<> relativeCabalFile
<> ", but it did not mention "
<> sourceFile
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically different behavior than the previous version: if debug is not enabled, the new version still relativizes the cabal file path, even though it's not printed.

I could create a version of logDebugM that takes a to-be-computed IO String message, but I don't think adding such a bespoke version is worth this relatively cheap call.

Comment on lines +22 to +30
loggerConfig :: IORef LoggerConfig
loggerConfig = unsafePerformIO $ newIORef (error "Logger not configured yet")
{-# NOINLINE loggerConfig #-}

initializeLogging :: Config region -> IO ()
initializeLogging cfg =
writeIORef loggerConfig $
LoggerConfig
{ debugEnabled = cfgDebug cfg
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a bit hacky and unprincipled, smuggling the config through the global environment. But I figured this was much neater than storing the config in R's environment and passing it through addFixityInfo.

I call this function immediately in all the entrypoints (main, ormolu, and for tests), so we should be good in principle. The only issue might be if someone imports from Ormolu's submodules + calls functions directly. I guess I could set a default logger config instead of erroring with "logger not configured yet".

@brandonchinn178 brandonchinn178 force-pushed the bchinn/fixity branch 2 times, most recently from f7d9a20 to 9af9080 Compare September 13, 2023 01:11
@mrkkrp
Copy link
Member

mrkkrp commented Oct 12, 2023

Could you add such a warning without introducing Ormolu.Logging?

@brandonchinn178
Copy link
Collaborator Author

brandonchinn178 commented Oct 12, 2023 via email

@brandonchinn178
Copy link
Collaborator Author

@mrkkrp do you have any thoughts on the above approaches?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it easier to debug fixity issues
2 participants