faiface / funky Goto Github PK
View Code? Open in Web Editor NEWthe best functional language ever
License: MIT License
the best functional language ever
License: MIT License
There are programs containing recursive type aliases (one fairly minimal example given below) where the type checker does not terminate trying to check if two overloads collide (in this case [see edit]:x
)
alias T = T
func x : Int = 0
func x : T = x
func main : IO = quit
Edit: The type checker also hangs on even simpler snippets like the following:
alias T = T
func x : T = false
func main : IO = quit
You can substitute false
with any term whose type is defined inside the language (via union
and record
) like ""
, []
, nothing
to reproduce this bug. Using primitive values (0
, 'x'
, etcetera) on the right side, rightly produces a type error! Native types (Int
, Float
, Char
) seem to be special-cased obviously.
The following malformed input causes the compiler to crash:
func main : IO = ;
Output:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x4e3bd8]
goroutine 1 [running]:
github.com/faiface/funky/parse.treeToFunc(0x575340, 0xc0002b64a0, 0xc0002b6460, 0xc0001eba30, 0x4, 0x4, 0x575340, 0xc0002b64a0)
/home/fmease/.go/src/github.com/faiface/funky/parse/definitions.go:249 +0x158
github.com/faiface/funky/parse.TreeToDefinitions(0x575380, 0xc0002b8990, 0x8, 0x575380, 0xc0002b8990, 0x0, 0x0)
/home/fmease/.go/src/github.com/faiface/funky/parse/definitions.go:60 +0x3ae
github.com/faiface/funky/parse.Definitions(0xc0000ab080, 0x6, 0x8, 0x0, 0xc0000ab080, 0x6, 0x8, 0x0)
/home/fmease/.go/src/github.com/faiface/funky/parse/definitions.go:20 +0x92
github.com/faiface/funky.Run(0x54a6a2, 0x4, 0x54a626, 0x4)
/home/fmease/.go/src/github.com/faiface/funky/run.go:58 +0x1454
main.main()
/home/fmease/.go/src/github.com/faiface/funky/interpreters/funkycmd/main.go:14 +0x4b
Further information: The semicolon "applied" to only one instead of two arguments (0;
and ;0
) behaves like the identity function. If "applied" to zero arguments, it is treated as if it is not actually there provided it's preceded by an expression which resolves to a value. 0 (;)
is treated as 0
, self (;) 0
as self 0
and so on. Contrarily, expressions like (;) (;) (;)
and (;) 0
cause a crash.
This code crashes the compiler:
func foo : a =
switch 0
case foozle
func bar : Int = 0
With this error message:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4d7643]
goroutine 1 [running]:
github.com/faiface/funky/expr.(*Switch).Map(0xc0002ae500, 0xc000563660, 0x51a780, 0x576901)
/home/fmease/.go/src/github.com/faiface/funky/expr/expr.go:128 +0x113
github.com/faiface/funky/types/typecheck.instExpr(0xc0002f0148, 0x576b60, 0xc0002ae500, 0x576920, 0xc0004ed410)
/home/fmease/.go/src/github.com/faiface/funky/types/typecheck/infer.go:576 +0x82
github.com/faiface/funky/types/typecheck.Infer(0xc0002b6e10, 0xc0006258d8, 0x576b60, 0xc0002ae500, 0xc0004ed110, 0x1, 0x1, 0x0, 0x0)
/home/fmease/.go/src/github.com/faiface/funky/types/typecheck/infer.go:178 +0x72
github.com/faiface/funky/compile.(*Env).TypeInfer(0xc000625d50, 0x0, 0x0, 0x0)
/home/fmease/.go/src/github.com/faiface/funky/compile/infer.go:40 +0x3f4
github.com/faiface/funky.Run(0x54a6a2, 0x4, 0x54a626, 0x4)
/home/fmease/.go/src/github.com/faiface/funky/run.go:89 +0x44f
main.main()
/home/fmease/.go/src/github.com/faiface/funky/interpreters/funkycmd/main.go:14 +0x4b
Because the parser does not handle the invalid sequence case x func
. I expected the error message nothing after binding
. The latter is output on input like (where EOF follows instead of the keyword func
):
func foo : a =
switch 0
case foozle
Edit: Relates to #6 (which is more general).
Per definition, the literal 0
is of type Int
and the literal 0.0
is of type Float
.
Thus, both lines below correctly fail to type-check:
(self : Int -> Int) 0.0
(self : Float -> Float) 0
For some reason though, type annotations directly placed on the literals seem to be ignored:
0.0 : Int # the whole expression is of type Float
0 : Float # the whole expression is of type Int
The expressions above pass the type-checker but clearly, they should not!
Edit: There might still be more cases like this. Another case:
'c' : Bool # type-checks
'c' : a # type-checks
Weirdly, this does not apply to string literals ("s" : Bool
is an error). Edit: I assume this bug only applies to primitive values (types Int
, Float
, Char
)!
If you use keywords (func
, alias
, record
, union
) in places where identifiers are expected, the compiler does not give a reasonable report but crashes. Faulty inputs might look like:
alias A = alias
, record union
or func func : Int = 0
.
The crashes are caused by nil pointer dereferences.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.