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

Smart casting does not work with ORM #23239

Closed
syobocat opened this issue Dec 22, 2024 · 0 comments · Fixed by #23241
Closed

Smart casting does not work with ORM #23239

syobocat opened this issue Dec 22, 2024 · 0 comments · Fixed by #23241
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@syobocat
Copy link
Contributor

syobocat commented Dec 22, 2024

Describe the bug

When I try to use smart casting with ORM, it does not compile.

Reproduction Steps

import db.sqlite

struct SomeStruct {
	foo int
	bar string
}

struct OtherStruct {
	baz f64
}

type SomeSum = SomeStruct | OtherStruct

fn main() {
	db := sqlite.connect(':memory:')!
	sql db {
		create table SomeStruct
	}!

	some := SomeSum(SomeStruct{})
	if some is SomeStruct {
		sql db {
			insert some into SomeStruct
		}!
	}
}

Expected Behavior

compile and run without error

Current Behavior

code.v:23:11: error: cannot use `SomeSum` as `SomeStruct`
   21 |     if some is SomeStruct {
   22 |         sql db {
   23 |             insert some into SomeStruct
      |                    ~~~~
   24 |         }!
   25 |     }

Possible Solution

No response

Additional Information/Context

Dynamic casting works:

import db.sqlite

struct SomeStruct {
	foo int
	bar string
}

struct OtherStruct {
	baz f64
}

type SomeSum = SomeStruct | OtherStruct

fn main() {
	db := sqlite.connect(':memory:')!
	sql db {
		create table SomeStruct
	}!

	some := SomeSum(SomeStruct{})
	definitely_some := some as SomeStruct
	sql db {
		insert definitely_some into SomeStruct
	}!
}

V version

V 0.4.9 3953445

Environment details (OS name and version, etc.)

V full version: V 0.4.9 c4aaa2e.3953445
OS: macos, macOS, 15.2, 24C101
Processor: 8 cpus, 64bit, little endian, Apple M3

getwd: /Users/syobon
vexe: /Users/syobon/.v/v
vexe mtime: 2024-12-22 04:45:19

vroot: OK, value: /Users/syobon/.v
VMODULES: OK, value: /Users/syobon/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.5 (Apple Git-154)
Git vroot status: weekly.2024.49-140-g39534459
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.6)
emcc version: N/A
thirdparty/tcc status: thirdparty-macos-arm64 713692d4

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Huly®: V_0.6-21673

@syobocat syobocat added the Bug This tag is applied to issues which reports bugs. label Dec 22, 2024
@Delta456 Delta456 self-assigned this Dec 22, 2024
@felipensp felipensp added Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants