Skip to content

Conversation

@terror
Copy link

@terror terror commented Dec 4, 2025

Resolves: #1637

This diff adds a typeApplications option to function restrictions, allowing users to require or forbid visible type arguments on specific functions. The primary use case is enforcing refactor-safe usage of polymorphic functions like fromIntegral and show, where implicit type inference can silently produce incorrect behaviour after type changes.

E.g., you're now able to specify:

- functions:
  - {name: fromIntegral, typeApplications: required}
  - {name: show, typeApplications: required}

Where fromIntegral x will be flagged with "Use visible type application", while fromIntegral @Int @Int64 x will be accepted. The option also supports forbidden for cases where type applications should be disallowed.

Comment on lines +346 to +358
pure Restrict
{ restrictType = restrictType
, restrictDefault = b
, restrictName = []
, restrictAs = mempty
, restrictAsRequired = mempty
, restrictImportStyle = mempty
, restrictQualifiedStyle = mempty
, restrictTypeApp = Nothing
, restrictWithin = []
, restrictIdents = NoRestrictIdents
, restrictMessage = Nothing
}
Copy link
Author

@terror terror Dec 4, 2025

Choose a reason for hiding this comment

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

Aside from adding restrictTypeApp, this is strictly a style refactor to make it more apparent as to what's going on. If this doesn't align with how we proceed elsewhere I'm happy to revert!

]
restrictTypeApp <- parseFieldOpt "typeApplications" v >>= maybeParseEnum
[ ("required" , TypeAppRequired)
, ("forbidden", TypeAppForbidden)
Copy link
Author

Choose a reason for hiding this comment

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

I'm questioning the need for a forbidden variant here, I don't see a strong use case for it in the original issue 🤔

@terror terror force-pushed the forbid-from-integral branch from bad6c5d to eb2e7d4 Compare December 4, 2025 20:24
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 possible to forbid "fromIntegral without visible type arguments"

1 participant