X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypecheck%2FTcSplice.lhs;h=51cf39282bc5fc98f9b55e9932e8754937a97cfc;hb=0dac952932514c931b00b1fae555ebde79f2b4db;hp=27656c9d904ff59e3f4ef09aae88e62069efe5fc;hpb=c7b31ad06fefeebd9ef912b6db4f3257be1f7ca2;p=ghc-hetmet.git diff --git a/compiler/typecheck/TcSplice.lhs b/compiler/typecheck/TcSplice.lhs index 27656c9..51cf392 100644 --- a/compiler/typecheck/TcSplice.lhs +++ b/compiler/typecheck/TcSplice.lhs @@ -720,25 +720,29 @@ reify th_name lookupThName :: TH.Name -> TcM Name lookupThName th_name@(TH.Name occ flavour) - = do { let rdr_name = thRdrName guessed_ns occ_str flavour - - -- Repeat much of lookupOccRn, becase we want - -- to report errors in a TH-relevant way - ; rdr_env <- getLocalRdrEnv - ; case lookupLocalRdrEnv rdr_env rdr_name of - Just name -> return name - Nothing | not (isSrcRdrName rdr_name) -- Exact, Orig - -> lookupImportedName rdr_name - | otherwise -- Unqual, Qual - -> do { mb_name <- lookupSrcOcc_maybe rdr_name - ; case mb_name of - Just name -> return name - Nothing -> failWithTc (notInScope th_name) } - } + = do { mb_ns <- mapM lookup [ thRdrName gns occ_str flavour + | gns <- guessed_nss] + ; case catMaybes mb_ns of + [] -> failWithTc (notInScope th_name) + (n:_) -> return n } -- Pick the first that works + -- E.g. reify (mkName "A") will pick the class A + -- in preference to the data constructor A where - -- guessed_ns is the name space guessed from looking at the TH name - guessed_ns | isLexCon (mkFastString occ_str) = OccName.dataName - | otherwise = OccName.varName + lookup rdr_name + = do { -- Repeat much of lookupOccRn, becase we want + -- to report errors in a TH-relevant way + ; rdr_env <- getLocalRdrEnv + ; case lookupLocalRdrEnv rdr_env rdr_name of + Just name -> return (Just name) + Nothing | not (isSrcRdrName rdr_name) -- Exact, Orig + -> do { name <- lookupImportedName rdr_name + ; return (Just name) } + | otherwise -- Unqual, Qual + -> lookupSrcOcc_maybe rdr_name } + + -- guessed_ns are the name spaces guessed from looking at the TH name + guessed_nss | isLexCon (mkFastString occ_str) = [OccName.tcName, OccName.dataName] + | otherwise = [OccName.varName, OccName.tvName] occ_str = TH.occString occ tcLookupTh :: Name -> TcM TcTyThing