Skip to content

Commit

Permalink
Fix #836 (#837)
Browse files Browse the repository at this point in the history
* add witness of bug

* fix witness of bug

* fix 836
  • Loading branch information
jcp19 authored Feb 5, 2025
1 parent 1d208a9 commit 67402a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ logger.log
*.interp
/gen/
/.gobra/
gobra_tmp/

.bloop/
.metals/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ trait GhostExprTyping extends BaseTyping { this: TypeInfoImpl =>
}
predWellDef ++ error(n, "Cannot reveal a predicate access.", n.pred.reveal)

case PTypeOf(e) => isExpr(e).out
case PTypeOf(e) =>
val isExp = isExpr(e).out
if (isExp.isEmpty) {
val typ = underlyingType(exprType(e))
error(e, s"typeOf expects an argument of an interface type, but got $e instead.", !typ.isInstanceOf[InterfaceT])
} else
isExp
case PTypeExpr(t) => isType(t).out
case n@ PIsComparable(e) => typOfExprOrType(e) match {
case t if isInterfaceType(t) => noMessages
Expand Down
15 changes: 15 additions & 0 deletions src/test/resources/regressions/issues/000836.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

package issue836

func test1() {
var x int
//:: ExpectedOutput(type_error)
assert typeOf(x) == type[int]
}

func test2() {
var x interface{} = int(1)
assert typeOf(x) == type[int]
}

0 comments on commit 67402a2

Please sign in to comment.