Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,239
    • Issues 5,239
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 565
    • Merge requests 565
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19288
Closed
Open
Issue created Jan 31, 2021 by Kyle Ehrlich@KyleDavidE

Type literals in Reflection of type constructor kinds leads to SafeHaskell violation

Summary

Data.Typeable.Internal#mkTypeLitFromString has a typo which causes type Natural literals are tagged with the type Symbol type constructor. This can be used to get a TypeRep Nat that is equal to the true TypeRep Symbol.

Steps to reproduce

Run this program:

{-# LANGUAGE DataKinds, KindSignatures, PolyKinds, TypeOperators, Safe #-}

module Main where

import Data.Maybe
import Data.Proxy
import Type.Reflection
import GHC.TypeLits

data Dat (x :: Proxy 1) = MkD1

evil :: Maybe (Nat :~~: Symbol)
evil = eqTypeRep (case (typeRepKind (typeRep :: TypeRep Dat)) of 
                          (Fun (App _ x) _) -> typeRepKind x)
                 (typeRep :: TypeRep Symbol)


main :: IO ()
main = print (isJust evil)

The program prints True. This could easily be used to make an unsafeCast.

Expected behavior

The program prints False

Environment

  • GHC version used: 8.10.3
Edited Jan 31, 2021 by Kyle Ehrlich
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking