summaryrefslogtreecommitdiff
path: root/compiler/deSugar/DsUtils.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2017-01-04 17:47:13 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2017-01-05 08:51:46 +0000
commitbaf9ebe55a51827c0511b3a670e60b9bb3617ab5 (patch)
treea43f640a064859e302a09b5ecb87d3f59ba47f12 /compiler/deSugar/DsUtils.hs
parentc909e6ec333667878b17f127f75204a14256340f (diff)
downloadhaskell-baf9ebe55a51827c0511b3a670e60b9bb3617ab5.tar.gz
Ensure nested binders have Internal Names
This is a long-standing bug. A nested (non-top-level) binder in Core should not have an External Name, like M.x. But - Lint was not checking this invariant - The desugarer could generate programs that failed the invariant. An example is in tests/deSugar/should_compile/T13043, which had let !_ = M.scState in ... This desugared to let ds = case M.scSate of M.scState { DEFAULT -> () } in case ds of () -> ... We were wrongly re-using that scrutinee as a case binder. And Trac #13043 showed that could ultimately lead to two top-level bindings with the same closure name. Alas! - The desugarer had one other place (in DsUtils.mkCoreAppDs) that could generate bogus code This patch fixes all three bugs, and adds a regression test.
Diffstat (limited to 'compiler/deSugar/DsUtils.hs')
-rw-r--r--compiler/deSugar/DsUtils.hs11
1 files changed, 6 insertions, 5 deletions
diff --git a/compiler/deSugar/DsUtils.hs b/compiler/deSugar/DsUtils.hs
index cc621d5d4f..290c172a14 100644
--- a/compiler/deSugar/DsUtils.hs
+++ b/compiler/deSugar/DsUtils.hs
@@ -40,14 +40,14 @@ module DsUtils (
#include "HsVersions.h"
-import {-# SOURCE #-} Match ( matchSimply )
+import {-# SOURCE #-} Match ( matchSimply )
+import {-# SOURCE #-} DsExpr ( dsLExpr )
import HsSyn
import TcHsSyn
import TcType( tcSplitTyConApp )
import CoreSyn
import DsMonad
-import {-# SOURCE #-} DsExpr ( dsLExpr )
import CoreUtils
import MkCore
@@ -55,7 +55,6 @@ import MkId
import Id
import Literal
import TyCon
--- import ConLike
import DataCon
import PatSyn
import Type
@@ -68,6 +67,7 @@ import UniqSet
import UniqSupply
import Module
import PrelNames
+import Name( isInternalName )
import Outputable
import SrcLoc
import Util
@@ -546,8 +546,9 @@ mkCoreAppDs _ (Var f `App` Type ty1 `App` Type ty2 `App` arg1) arg2
= Case arg1 case_bndr ty2 [(DEFAULT,[],arg2)]
where
case_bndr = case arg1 of
- Var v1 | isLocalId v1 -> v1 -- Note [Desugaring seq (2) and (3)]
- _ -> mkWildValBinder ty1
+ Var v1 | isInternalName (idName v1)
+ -> v1 -- Note [Desugaring seq (2) and (3)]
+ _ -> mkWildValBinder ty1
mkCoreAppDs s fun arg = mkCoreApp s fun arg -- The rest is done in MkCore