Skip to content
Merged
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
20 changes: 20 additions & 0 deletions server/src/e2e/tolk/testcases/types/basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,23 @@ fun main() {
}
------------------------------------------------------------------------
ok

========================================================================
Cyclic dependency with Cell in struct
========================================================================
struct SwapStep {
pool: address
minAmountOut: coins
nextStep: Cell<SwapStep>?
}

fun main() {
val foo = SwapStep{};
//! ^ SwapStep
val step = foo.nextStep!
//! ^ Cell<SwapStep>
val loadedStep = foo.nextStep!.load()
//! ^ SwapStep
}
------------------------------------------------------------------------
ok
15 changes: 10 additions & 5 deletions server/src/languages/tolk/TypeInferer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,11 +670,16 @@ export class TypeInferer {

private inferTypeFromResolved(resolved: NamedNode): Ty | null {
if (resolved instanceof Struct) {
const baseTy = new StructTy(
resolved.fields().map(it => this.inferType(it.typeNode()) ?? UnknownTy.UNKNOWN),
resolved.name(),
resolved,
)
const fieldTypes = resolved.fields().map(it => {
try {
return this.inferType(it.typeNode()) ?? UnknownTy.UNKNOWN
} catch {
// cyclic dependency
return UnknownTy.UNKNOWN
}
})

const baseTy = new StructTy(fieldTypes, resolved.name(), resolved)

const typeParameters = resolved.typeParameters()
if (typeParameters.length > 0) {
Expand Down
Loading