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

"warning" comments ignored for method-style calls #386

Open
matil019 opened this issue Nov 19, 2019 · 1 comment
Open

"warning" comments ignored for method-style calls #386

matil019 opened this issue Nov 19, 2019 · 1 comment

Comments

@matil019
Copy link
Member

You can add an arbitrary warnings to functions by adding a documentation comment starting with warning:. However, if such comments are added to members of data or class and they are called by "method-style" (what is the correct term for this?), the compiler doesn't warn about them.

Example:

module Main where

data Foo = Foo Int
    where
    --- warning: don't use this!
    get :: Foo -> Int
    get (Foo x) = x

class Hello a where
    --- warning: don't use this either!
    hello :: a -> String

instance Hello Foo where
    hello (Foo x) = show x

main :: IO ()
main = do
    let foo = Foo 1
    -- these get warnings
    println (Foo.get foo)
    println (hello foo)
    -- but these don't
    println foo.get
    println foo.hello

The output of the compiler:

$ java -jar fregec.jar -ascii Main.fr
W Main.fr:20: Foo.get: don't use this!
W Main.fr:21: Hello.hello: don't use this either!
calling: javac -cp fregec.jar:. -d . -sourcepath . -encoding UTF-8 ./Main.java
@Ingo60
Copy link
Member

Ingo60 commented Nov 19, 2019

This is because the method names are resolved at different times.
The plain names or the ones prefixed with a type name will be resolved in pass 4 (I think).
Whereas the others are resolved during type checking (type directed name resolution).

It would probably possible to emit the warning then as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants