Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ class SigmaTyper(val builder: SigmaBuilder,
case (Ident(GetVarFunc.name | ExecuteFromVarFunc.name, _), Seq(id: Constant[SNumericType]@unchecked))
if id.tpe.isNumType =>
Seq(ByteConstant(SByte.downcast(id.value.asInstanceOf[AnyVal])).withSrcCtx(id.sourceContext))
case (Ident(ExecuteFromSelfRegFunc.name, _), Seq(id: Constant[SNumericType]@unchecked))
if id.tpe.isNumType =>
Seq(IntConstant(SInt.downcast(id.value.asInstanceOf[AnyVal])).withSrcCtx(id.sourceContext))
case (Ident(ExecuteFromSelfRegWithDefaultFunc.name, _), Seq(id: Constant[SNumericType]@unchecked, default))
if id.tpe.isNumType =>
Seq(IntConstant(SInt.downcast(id.value.asInstanceOf[AnyVal])).withSrcCtx(id.sourceContext), default)
case (Ident(SContextMethods.getVarFromInputMethod.name, _),
Seq(inputId: Constant[SNumericType]@unchecked, varId: Constant[SNumericType]@unchecked))
if inputId.tpe.isNumType && varId.tpe.isNumType =>
Expand Down
16 changes: 16 additions & 0 deletions sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,24 @@ class SigmaTyperTest extends AnyPropSpec
typecheck(env, "executeFromVar[Boolean](1)") shouldBe SBoolean
}

property("executeFromSelfReg") {
// Test with Int literal (should work with automatic downcast)
typecheck(env, "executeFromSelfReg[Boolean](4)") shouldBe SBoolean
typecheck(env, "executeFromSelfReg[Int](5)") shouldBe SInt
typecheck(env, "executeFromSelfReg[Long](6)") shouldBe SLong

// Test with numeric types that need downcast to Int
typecheck(env, "executeFromSelfReg[Boolean](4L)") shouldBe SBoolean
typecheck(env, "executeFromSelfReg[Int](5L)") shouldBe SInt
}

property("executeFromSelfRegWithDefault") {
// Test with Int literal (should work with automatic downcast)
typecheck(env, "executeFromSelfRegWithDefault[Boolean](4, getVar[Boolean](1).get)") shouldBe SBoolean

// Test with numeric types that need downcast to Int
typecheck(env, "executeFromSelfRegWithDefault[Boolean](4L, getVar[Boolean](1).get)") shouldBe SBoolean
typecheck(env, "executeFromSelfRegWithDefault[Int](5L, 10)") shouldBe SInt

an[TyperException] should be thrownBy {
typecheck(env, "executeFromSelfRegWithDefault[Boolean](4, getVar[Int](1).get)")
Expand Down