Skip to content

Conversation

@kl0tl
Copy link
Member

@kl0tl kl0tl commented Sep 19, 2020

As noticed by @hdgarrood in #3927 (comment), merely being exported isn’t a sufficient condition for a newtype to be unwraped when solving Coercible constraints because of internal modules.

This pull request requires newtypes constructors to be imported for them to be unwrapable and ensures UnusedDctorImport warnings aren’t emitted for newtype constructors imported only for the sake of solving Coercible constraints.

@rhendric
Copy link
Member

Is the new shouldNotWarnWith infrastructure necessary? I think existing tests accomplish this by living in purs/warning and having empty .out files, unless I'm misunderstanding what you're trying to do.

@kl0tl
Copy link
Member Author

kl0tl commented Sep 20, 2020

Is the new shouldNotWarnWith infrastructure necessary? I think existing tests accomplish this by living in purs/warning and having empty .out files, unless I'm misunderstanding what you're trying to do.

It didn’t occur to me that empty golden tests were equivalent to checking for the absence of warnings 🤦 I removed shouldNotWarnWith and the associated changes.

let usedImports = fold $ M.lookup moduleName usedImportsByModuleName
usedImports' = foldl' (flip $ \(fromModuleName, newtypeCtorName) ->
M.alter (Just . (fmap DctorName newtypeCtorName :) . fold) fromModuleName) usedImports checkCoercedNewtypeCtorsImports
censor (addHint (ErrorInModule moduleName)) $ lintImports checked exEnv' usedImports'
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add a comment here saying that we need to wait until after type checking to lint imports because newtype constructors may be marked as used as part of Coercible solving?

-- since this way, we can provide good error messages
-- during instance resolution.
, checkCoercedNewtypeCtorsImports :: S.Set (ModuleName, Qualified (ProperName 'ConstructorName))
-- ^ Newtype constructors imports required to solve Coercible constraints
Copy link
Contributor

Choose a reason for hiding this comment

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

This field is only for keeping track of newtype constructors which have been used so that we don't emit unused import warnings for them, right? If so could you please mention that here?

@kl0tl
Copy link
Member Author

kl0tl commented Oct 8, 2020

I added some comments, let me know if this is clear enough!

-- Imports cannot be linted before type checking because we need to
-- known which newtype constructors are used to solve Coercible
-- constraints in order to not report them as unused.
censor (addHint (ErrorInule moduleName)) $ lintImports checked exEnv' usedImports'
Copy link
Contributor

Choose a reason for hiding this comment

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

typo here? I think this is causing CI to fail

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess I was too tired even for adding comments properly 🤦

@hdgarrood
Copy link
Contributor

Looks great 👍 please feel free to hit merge once CI is passing

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.

3 participants