Skip to content

Commit

Permalink
compiler: add checks to ensure you cannot compare against Void type (…
Browse files Browse the repository at this point in the history
…causes JVM verify error)
  • Loading branch information
briansfrank committed Jun 30, 2024
1 parent 789e39c commit df22ed5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/compiler/fan/steps/CheckErrors.fan
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,19 @@ class CheckErrors : CompilerStep
err("Incomparable types '$lhs.ctype' and '$rhs.ctype'", lhs.loc)
return false
}

if (lhs.ctype.isVoid)
{
err("Cannot compare to Void type", lhs.loc)
return false
}

if (rhs.ctype.isVoid)
{
err("Cannot compare to Void type", rhs.loc)
return false
}

return true
}

Expand Down
27 changes: 27 additions & 0 deletions src/testCompiler/fan/CheckErrorsTest.fan
Original file line number Diff line number Diff line change
Expand Up @@ -1884,5 +1884,32 @@ class CheckErrorsTest : CompilerTest
])
}


//////////////////////////////////////////////////////////////////////////
// Void Compares
//////////////////////////////////////////////////////////////////////////

Void testVoidCompares()
{
verifyErrors(
"""class Foo
{
Void bar()
{
if (obj == foo) return // line 5
if (foo != obj) return // line 6
if (obj === foo) return // line 7
}
Obj? obj() { null }
Void foo() {}
}""",
[
5, 17, "Cannot compare to Void type",
6, 10, "Cannot compare to Void type",
7, 18, "Cannot compare to Void type",
])
}
}

0 comments on commit df22ed5

Please sign in to comment.