Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Partial" pattern match causes segfault at runtime #2469

Closed
SuprDewd opened this issue Feb 22, 2017 · 2 comments
Closed

"Partial" pattern match causes segfault at runtime #2469

SuprDewd opened this issue Feb 22, 2017 · 2 comments
Assignees
Labels
backend: ghc Haskell code generation backend ("MAlonzo") backend: js JavaScript generation backend compiler-treeless type: bug Issues and pull requests about actual bugs varying-arity
Milestone

Comments

@SuprDewd
Copy link

SuprDewd commented Feb 22, 2017

Using Agda 2.5.2, the following code type checks, but when executed (agda -c crash.agda && ./crash), it segfaults.

module crash where

open import Data.Nat.Properties.Simple
open import Data.Nat
open import Data.Product
open import Data.Sum
open import Data.Maybe
open import Data.Empty
open import IO
open import Data.Unit
open import Agda.Builtin.IO renaming (IO to BIO)
open import Data.String

data F : Set where
  [] : F zero
  _∷1 :  {n}  F n  F (suc n)
  _∷2 :  {n}  F n  F (suc (suc n))

f :  k  F (suc k)  F k ⊎ Maybe ⊥
f zero a = inj₂ nothing
f k (xs ∷1) = inj₂ nothing
-- to (suc k) xs = inj₂ nothing  -- This is fine
f (suc k) = λ xs  inj₂ nothing  -- This segfaults

myshow : F 1 ⊎ Maybe ⊥  String
-- myshow (inj₁ b) = ""        -- This is fine
myshow (inj₁ (b ∷1)) = ""      -- This segfaults
myshow _ = ""

main : BIO ⊤
main = run (putStrLn (myshow (f 1 ([] ∷2))))

This was also tested using Agda 2.5.1.1, where it fails to type check with the following message:

crash.agda:20,1-23,10
Incomplete pattern matching for f. Missing cases:
  f (suc _) (_∷2 {._} _)
when checking the definition of f

If one looks closely, the pattern matching for f is complete, so it may be that the type checker was made smarter for 2.5.2, but somewhere the runtime is still unable to work out the logic.

@nad nad added type: bug Issues and pull requests about actual bugs backend: ghc Haskell code generation backend ("MAlonzo") varying-arity labels Feb 22, 2017
@nad nad added this to the 2.5.3 milestone Feb 22, 2017
@phile314 phile314 self-assigned this Feb 22, 2017
@phile314 phile314 added compiler-treeless backend: js JavaScript generation backend labels Feb 22, 2017
phile314 added a commit to phile314/agda that referenced this issue Feb 22, 2017
Varying arity functions with unused arguments got compiled incorrectly.
phile314 added a commit to phile314/agda that referenced this issue Feb 22, 2017
Varying arity functions with unused arguments got compiled incorrectly.
@phile314
Copy link
Member

Fixed in the GHC backend, still a problem in the JS backend.

@phile314 phile314 reopened this Feb 23, 2017
@phile314 phile314 removed compiler-treeless backend: ghc Haskell code generation backend ("MAlonzo") labels Feb 23, 2017
@nad nad added compiler-treeless backend: ghc Haskell code generation backend ("MAlonzo") labels Feb 23, 2017
@nad
Copy link
Contributor

nad commented Feb 23, 2017

I restored the labels that you removed. Sometimes we search for fixed issues using labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: ghc Haskell code generation backend ("MAlonzo") backend: js JavaScript generation backend compiler-treeless type: bug Issues and pull requests about actual bugs varying-arity
Projects
None yet
Development

No branches or pull requests

3 participants