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

Segfault when accessing an element of an array of float throught a polymorphic method. #4473

Closed
vicuna opened this Issue Jan 5, 2008 · 3 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link
Collaborator

vicuna commented Jan 5, 2008

Original bug ID: 4473
Reporter: sol
Status: closed (set by @garrigue on 2008-01-18T03:54:19Z)
Resolution: fixed
Priority: normal
Severity: crash
Version: 3.10.1
Fixed in version: 3.10+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @yakobowski

Bug description

Example:

class xyz =
object
method nth : 'a . int -> 'a array -> 'a = fun x a -> a.(x mod Array.length a)
end

Running this with an array of string, int or options... works fine. But an array of float causes a segfault.
Tested in versions: 3.09.3 on mac osx 10
and 3.10.0 on windows xp.

However the following works fine:

let nth : int -> 'a array -> 'a = fun x a -> a.(x mod Array.length a)

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Jan 7, 2008

Comment author: @xavierleroy

Confirmed in 3.10.1. The culprit is probably Typeopt.array_element_kind, which doesn't know about universally-quantified type variables.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Jan 7, 2008

Comment author: sol

The following works as a workaround:
First create a function and assign it to a class method.

let nth : 'a array -> int -> 'a = fun a i -> a.(i mod Array.length a)

class c =
object
method nth : 'a . 'a array -> int -> 'a = nth
end

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Jan 18, 2008

Comment author: @garrigue

I commited the fix for Typeopt.array_element_kind in CVS.

@vicuna vicuna closed this Jan 18, 2008

@vicuna vicuna added the bug label Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.