Skip to content

Commit 900880a

Browse files
committed
std/comptime: add the ActualSource method to comptimeTypeInfo
1 parent eed574d commit 900880a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

std/comptime/type.jule

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ impl comptimeTypeInfo {
8686
// Returns source type of strict type alias.
8787
fn Source(self): comptimeTypeInfo
8888

89+
// Returns actual source type of strict type alias.
90+
fn ActualSource(self): comptimeTypeInfo
91+
8992
// Returns kind of type.
9093
// Returns as constant expression.
9194
fn Kind(self): int

std/jule/sema/comptime.jule

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,21 @@ impl comptimeTypeInfo {
10121012
ret buildComptimeTypeInfoData(e.s, s.Source)
10131013
}
10141014

1015+
fn _ActualSource(mut &self, mut &e: &eval, mut &fc: &ast::FuncCallExpr): &Value {
1016+
if len(fc.Args) > 0 {
1017+
e.pushErr(fc.Args[0].Token, log::ArgumentOverflow, "ActualSource")
1018+
ret nil
1019+
}
1020+
s := self.base.SoftStruct()
1021+
isStrict := s != nil && s.Source != nil
1022+
if !isStrict {
1023+
e.pushErr(fc.Token, log::InvalidTypeForFunc, self.base.Str(), "ActualSource")
1024+
ret nil
1025+
}
1026+
mut t := &Type{Kind: self.base.ActualKind()}
1027+
ret buildComptimeTypeInfoData(e.s, t)
1028+
}
1029+
10151030
fn subIdent(mut &self, &ident: str): &Value {
10161031
match ident {
10171032
| "Hash":
@@ -1028,6 +1043,13 @@ impl comptimeTypeInfo {
10281043
},
10291044
}
10301045
ret buildAsComptimeMethodData(method)
1046+
| "ActualSource":
1047+
mut method := &FuncIns{
1048+
caller: fn(mut &e: &eval, mut &fc: &ast::FuncCallExpr, mut &_: &Value): &Value {
1049+
ret self._ActualSource(e, fc)
1050+
},
1051+
}
1052+
ret buildAsComptimeMethodData(method)
10311053
| "Strict":
10321054
mut method := &FuncIns{
10331055
caller: fn(mut &e: &eval, mut &fc: &ast::FuncCallExpr, mut &_: &Value): &Value {

0 commit comments

Comments
 (0)