Skip to content

Use export list of Main module in function TcRnDriver.hs:check_main. Fix #16453.

Roland Senn requested to merge RolandSenn/ghc:T16453 into master

The function compiler/typecheck/TcRnDriver.hs:check_main calls compiler/GHC/Rename/Env.hs:lookupOccRn_maybe to collect the main function(s) in scope of the Main module. If there are multiple main functions in scope, lookupOccRn_maybe throws the ambigous main error mentioned in #16453 (closed).

This MR:

  • Provide the export list of the Main module as parameter to the check_main function.
  • Instead of lookupOccRn_maybe call the function lookupInfoOccRn. It returns the list mains_all of all the main functions in scope.
  • Select from this list mains_all all main functions that are in the export list.
  • If this new list contains exactly one single main function, then typechecking continues.
  • Otherwise issue an appropriate error message.

Note: main function always means the function name from the main-is spec.

Edited by Ryan Scott

Merge request reports