Skip to content

-fdefer-out-of-scope-variables should also defer ambiguous occurrences

Motivation

Use of -fdefer-out-of-scope-variables indicates that a user wants to keep trying to run code even if the variable names cannot be resolved. But there's one case where GHC doesn't live up to that intent.

import Prelude
head = "^-^"
main = print head

GHC says:

$ ghc -fdefer-out-of-scope-variables Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )

Test.hs:3:14: error:
    Ambiguous occurrence ‘head’
    It could refer to either ‘Prelude.head’,
                             imported from ‘Prelude’ at Test.hs:1:1-14
                             (and originally defined in ‘GHC.List’)
                          or ‘Main.head’, defined at Test.hs:2:1

and fails to load the module

Proposal

I believe this should successfully load the module, but fail at runtime because head couldn't be resolved.

Edited by Chris Smith
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information