Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lax compiler causes problem with Result[] object encapsulating base of inherited object #1796

Closed
mjfh opened this issue Oct 2, 2023 · 1 comment

Comments

@mjfh
Copy link
Contributor

mjfh commented Oct 2, 2023

The following program compiles and runs ok.

import
  results, unittest2

type
  ARef = ref AObj
  AObj = object of RootObj

  BRef = ref BObj
  BObj = object of AObj

# Statement compiles all right and runs ok
discard Result[ARef,void].ok(BRef())
discard Result[void,ARef].err(BRef())

# Statements compile all right 
expect ObjectAssignmentDefect:
  # Will throw a run-time exception
  discard Result[AObj,void].ok(BObj())

expect ObjectAssignmentDefect:
  # Will throw a run-time exception
  discard Result[void,AObj].err(BObj())

The problem is that the Result[] clause does not work properly when encapsulating the base object AObj while given some inherited object BObj. But the compiler accepts that construction as valid.

mjfh added a commit that referenced this issue Oct 2, 2023
details:
 This does not affect the legacy interface which is the production one,
 currently.
mjfh added a commit that referenced this issue Oct 2, 2023
details:
 This does not affect the legacy interface which is the production one,
 currently.
@arnetheduck
Copy link
Member

This is what the language works like (ie it has got nothing to do with Result):

type
  AObj = object of RootObj
  BObj = object of AObj

var x: AObj
x = BObj() # Raises ObjectAssignmentDefect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants