Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007330OCamltypingpublic2016-08-20 19:482017-03-03 17:44
ReporterElarnon 
Assigned Togarrigue 
PrioritynormalSeveritycrashReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.03.0 
Target VersionFixed in Version4.04.0 +dev / +beta1 / +beta2 
Summary0007330: Missing exhaustivity check for extensible variant
DescriptionWhen compiling non-exhaustive pattern-matching (i.e. without a catch-all clause) on extensible variant types in 4.03.0:

 (a) No warning is emitted at compile time. 4.02.3 properly emits a Warning 8.

 (b) Ill-typed code is executed at runtime. 4.02.3 properly raises a Match_failure exception.

This behavior was reproduced using opam's 4.03.0 (i.e. no flambda) version on OSX, Debian testing and Archlinux machines, see attached file for code that compiles without warning in 4.03.0 but segfaults when executed. It is still present in opam's 4.04.0+beta1.
TagsNo tags attached.
Attached Files? file icon crash.ml [^] (167 bytes) 2016-08-20 19:48 [Show Content]

- Relationships

-  Notes
(0016217)
gasche (developer)
2016-08-21 16:54

git bisect tells me that the issue was introduced in the gadt-warnings branch:

commit c88f3d0634f39fb920fc06ffbc4705ad6bea29f5
Author: Jacques Garrigue <garrigue at math.nagoya-u.ac.jp>
Date: Tue May 19 22:52:21 2015 +0000

    Improved exhaustiveness warnings for GADTs, with non-deterministic in type_pat
    
    git-svn-id: http://caml.inria.fr/svn/ocaml/branches/gadt-warnings@16133 [^] f963ae5c-01c2-4b8c-9fe0-0dff7051ff02


https://github.com/ocaml/ocaml/commit/c88f3d0634f39fb920fc06ffbc4705ad6bea29f5 [^]
(0016218)
garrigue (manager)
2016-08-22 03:03

Fixed in 4.04 branch by commit b4b21d6.

Extra extension constructors were represented by an untypable pattern.
Fixed by switching to a variable, but this requires hacks for nice warnings.
(0016395)
frisch (developer)
2016-10-07 10:24

I've cherry-picked this from 4.04 to trunk (commit 49504101eee96686a76c64910450364f2e958b87).
(0016503)
edwin (reporter)
2016-11-03 15:48

I've just run into this segfault, when having a non-exhaustive match on an exception (4.02.3 and 4.04.0+trunk correctly print the warning and raise Match_failure, 4.03.0 segfaults), I think this is because exceptions are like open variants internally.

Here are two testcases, please consider adding them to your testsuite as well:

(* ocamlopt excrash.ml -o excrash && ./excrash *)
exception Custom of string list
type ('a,'b) result = Ok of unit | Error of 'b
let failme () = Error (Failure "test")

let handle = function
  | Ok () -> 0
  | Error (Custom lst) -> List.length lst

let () = failme () |> handle |> string_of_int |> print_endline

(* ocamlopt varcrash.ml -o varcrash && ./varcrash *)
type t = ..

type t += Custom of string list
type t += A of string

type ('a,'b) result = Ok of 'a | Error of 'b
let failme () = Error (A "test")

let handle = function
  | Ok () -> 0
  | Error (Custom lst) -> List.length lst

let () = failme () |> handle |> string_of_int |> print_endline

- Issue History
Date Modified Username Field Change
2016-08-20 19:48 Elarnon New Issue
2016-08-20 19:48 Elarnon File Added: crash.ml
2016-08-21 16:54 gasche Note Added: 0016217
2016-08-22 03:03 garrigue Note Added: 0016218
2016-08-22 03:03 garrigue Status new => resolved
2016-08-22 03:03 garrigue Fixed in Version => 4.04.0 +dev / +beta1 / +beta2
2016-08-22 03:03 garrigue Resolution open => fixed
2016-08-22 03:03 garrigue Assigned To => garrigue
2016-10-07 10:24 frisch Note Added: 0016395
2016-11-03 15:48 edwin Note Added: 0016503
2017-02-23 16:36 doligez Category Incoming => -Incoming
2017-03-03 17:44 doligez Category -Incoming => typing


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker